﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using PMisuseAn.io;

namespace PMisuseAn
{
    /// <summary>
    /// Interaction logic for AddActorAttributeWindow.xaml
    /// </summary>
    /// 
    public partial class AddActorAttributeWindow : Window
    {
        public Attribute source_attribute;
        public Attribute x_attribute;
        AddActorWindow aaw_;
        ContextInterface ci_;
        EmulationEnvironmentWindow eew_;
        string attName;

        public List<string> containedimplications;
        public List<string> containedaggregations;

        public static bool isActorCall = false;
        public bool isNewAttribute = false;
        List<string> attributeNames;
        public AddActorAttributeWindow(EmulationEnvironmentWindow eew)
        {
            InitializeComponent();
            eew_ = eew;
            isActorCall = false;
            //yes_p_rd.IsEnabled = false;
            //yes_p_rd.IsChecked = false;
            //no_p_rd.IsEnabled = false;
            //no_p_rd.IsChecked = false;
            reloadAttInComboBox();
            //reloadAttTypeOfComboBox();
            attributeNames = MisUseAnObjectsDB.loadAllAttributeNames(MainWindow.clusterName);

        }

        public AddActorAttributeWindow(AddActorWindow aaw)
        {
            InitializeComponent();
            aaw_ = aaw;
            isActorCall = true;
            reloadAttInComboBox();
            attributeNames = MisUseAnObjectsDB.loadAllAttributeNames(MainWindow.clusterName);
            //reloadAttTypeOfComboBox();
        }

        public AddActorAttributeWindow(AddActorWindow aaw, Attribute source_attribute_)
        {
            InitializeComponent();
            aaw_ = aaw;

            source_attribute = source_attribute_;
            isActorCall = false;
            //yes_p_rd.IsEnabled = false;
            //no_p_rd.IsEnabled = false;
            //yes_p_rd.IsChecked = false;
            //no_p_rd.IsChecked = false;

            //if (source_attribute.isPrivate)
            //{
            //    yes_p_rd.IsChecked = true;
            //}
            //else
            //{
            //    no_p_rd.IsChecked = false;
            //}
            attributeNames = MisUseAnObjectsDB.loadAllAttributeNames(MainWindow.clusterName);
            reloadAttInComboBox();

            att_name_cb.Text = source_attribute.name;
            att_description.Text = source_attribute.description;
            //attributeValue_cb.Text = source_attribute.attributeValue;

            attributeValue_cb.Text = source_attribute.sensitivityLevel.ToString();
            obfuscation_level_cb.Text = source_attribute.obfuscationLevel.ToString();


            //if (source_attribute.personallyIdentifiable == true)
            //{
            //    per_id_rd_y.IsChecked = true;
            //}
            //else
            //{
            //    per_id_rd_n.IsChecked = true;
            //}

            if (source_attribute.literalType.Equals("[numeric]"))
            {
                numeric_l.IsChecked = true;
            }
            else if (source_attribute.literalType.Equals("[string]"))
            {
                string_l.IsChecked = true;
            }
            else if (source_attribute.literalType.Equals("[boolean]"))
            {
                boolean_l.IsChecked = true;
            }

            if (source_attribute.category.Equals("agentAttribute"))
            {
                categoryAgent.IsChecked = true;
            }
            else if (source_attribute.category.Equals("environmentalAttribute"))
            {
                categoryEnvironmental.IsChecked = true;
            }
            else if (source_attribute.category.Equals("regulatoryAttribute"))
            {
                categoryRegulatory.IsChecked = true;
            }

            reloadAggregationList(source_attribute);
            reloadImpliedFromToList(source_attribute);
            reloadAttributeDomainList(source_attribute);
            //reloadAttTypeOfComboBox();
            //reloadAttributeTypeOfList(source_attribute);

            //att_name_cb.IsEditable = false;
            att_name_cb.IsEnabled = false;
            att_description.IsEnabled = true;
            //per_id_rd_y.IsEnabled = true;
            //per_id_rd_n.IsEnabled = true;
            numeric_l.IsEnabled = true;
            string_l.IsEnabled = true;
            boolean_l.IsEnabled = true;
            categoryAgent.IsEnabled = true;
            categoryEnvironmental.IsEnabled = true;
            categoryRegulatory.IsEnabled = true;
            //implied_from_to_b.IsEnabled = true;
            aggregates_from_to_b.IsEnabled = true;
            att_domain_b.IsEnabled = true;
            ok_actor_att_b.IsEnabled = true;
        }

        public AddActorAttributeWindow(EmulationEnvironmentWindow eew, Attribute source_attribute_)
        {
            InitializeComponent();
            eew_ = eew;

            source_attribute = source_attribute_;
            isActorCall = false;
            //yes_p_rd.IsEnabled = false;
            //no_p_rd.IsEnabled = false;
            //yes_p_rd.IsChecked = false;
            //no_p_rd.IsChecked = false;

            //if (source_attribute.isPrivate)
            //{
            //    yes_p_rd.IsChecked = true;
            //}
            //else
            //{
            //    no_p_rd.IsChecked = false;
            //}
            attributeNames = MisUseAnObjectsDB.loadAllAttributeNames(MainWindow.clusterName);
            reloadAttInComboBox();

            att_name_cb.Text = source_attribute.name;
            att_description.Text = source_attribute.description;
            //attributeValue_cb.Text = source_attribute.attributeValue;

            attributeValue_cb.Text = source_attribute.sensitivityLevel.ToString();
            obfuscation_level_cb.Text = source_attribute.obfuscationLevel.ToString();

            //if (source_attribute.personallyIdentifiable == true)
            //{
            //    per_id_rd_y.IsChecked = true;
            //}
            //else
            //{
            //    per_id_rd_n.IsChecked = true;
            //}

            if (source_attribute.literalType.Equals("[numeric]"))
            {
                numeric_l.IsChecked = true;
            }
            else if (source_attribute.literalType.Equals("[string]"))
            {
                string_l.IsChecked = true;
            }
            else if (source_attribute.literalType.Equals("[boolean]"))
            {
                boolean_l.IsChecked = true;
            }

            if (source_attribute.category.Equals("agentAttribute"))
            {
                categoryAgent.IsChecked = true;
            }
            else if (source_attribute.category.Equals("environmentalAttribute"))
            {
                categoryEnvironmental.IsChecked = true;
            }
            else if (source_attribute.category.Equals("regulatoryAttribute"))
            {
                categoryRegulatory.IsChecked = true;
            }

            reloadAggregationList(source_attribute);
            reloadImpliedFromToList(source_attribute);
            reloadAttributeDomainList(source_attribute);
            //reloadAttTypeOfComboBox();
            //reloadAttributeTypeOfList(source_attribute);

            //att_name_cb.IsEditable = false;
            att_name_cb.IsEnabled = false;
            att_description.IsEnabled = true;
            //per_id_rd_y.IsEnabled = true;
            //per_id_rd_n.IsEnabled = true;
            numeric_l.IsEnabled = true;
            string_l.IsEnabled = true;
            boolean_l.IsEnabled = true;
            categoryAgent.IsEnabled = true;
            categoryEnvironmental.IsEnabled = true;
            categoryRegulatory.IsEnabled = true;
            //implied_from_to_b.IsEnabled = true;
            aggregates_from_to_b.IsEnabled = true;
            att_domain_b.IsEnabled = true;
            ok_actor_att_b.IsEnabled = true;
        }

        public AddActorAttributeWindow(ContextInterface ci, Attribute source_attribute_)
        {
            InitializeComponent();
            ci_ = ci;

            source_attribute = source_attribute_;
            isActorCall = false;
            //yes_p_rd.IsEnabled = false;
            //yes_p_rd.IsChecked = false;
            //no_p_rd.IsEnabled = false;
            //no_p_rd.IsChecked = false;
            attributeNames = MisUseAnObjectsDB.loadAllAttributeNames(MainWindow.clusterName);           
            reloadAttInComboBox();            

            att_name_cb.Text = source_attribute.name;
            att_description.Text = source_attribute.description;
            //attributeValue_cb.Text = source_attribute.attributeValue;

            attributeValue_cb.Text = source_attribute.sensitivityLevel.ToString();
            obfuscation_level_cb.Text = source_attribute.obfuscationLevel.ToString();

            //if (source_attribute.personallyIdentifiable == true)
            //{
            //    per_id_rd_y.IsChecked = true;
            //}
            //else
            //{
            //    per_id_rd_n.IsChecked = true;
            //}

            if (source_attribute.literalType.Equals("[numeric]"))
            {
                numeric_l.IsChecked = true;
            }
            else if (source_attribute.literalType.Equals("[string]"))
            {
                string_l.IsChecked = true;
            }
            else if (source_attribute.literalType.Equals("[boolean]"))
            {
                boolean_l.IsChecked = true;
            }

            if (source_attribute.category.Equals("agentAttribute"))
            {
                categoryAgent.IsChecked = true;
            }
            else if (source_attribute.category.Equals("environmentalAttribute"))
            {
                categoryEnvironmental.IsChecked = true;
            }
            else if (source_attribute.category.Equals("regulatoryAttribute"))
            {
                categoryRegulatory.IsChecked = true;
            }

            reloadAggregationList(source_attribute);
            reloadImpliedFromToList(source_attribute);
            reloadAttributeDomainList(source_attribute);
            //reloadAttTypeOfComboBox();
            //reloadAttributeTypeOfList(source_attribute);

            //att_name_cb.IsEditable = false;
            att_name_cb.IsEnabled = false;
            att_description.IsEnabled = true;
            //per_id_rd_y.IsEnabled = true;
            //per_id_rd_n.IsEnabled = true;
            numeric_l.IsEnabled = true;
            string_l.IsEnabled = true;
            boolean_l.IsEnabled = true;
            categoryAgent.IsEnabled = true;
            categoryEnvironmental.IsEnabled = true;
            categoryRegulatory.IsEnabled = true;
            //implied_from_to_b.IsEnabled = true;
            aggregates_from_to_b.IsEnabled = true;
            att_domain_b.IsEnabled = true;
            ok_actor_att_b.IsEnabled = true;
        }

        public AddActorAttributeWindow(ContextInterface ci)
        {
            InitializeComponent();
            ci_ = ci;

            isActorCall = false;
            //yes_p_rd.IsEnabled = false;
            //yes_p_rd.IsChecked = false;
            //no_p_rd.IsEnabled = false;
            //no_p_rd.IsChecked = false;
            attributeNames = MisUseAnObjectsDB.loadAllAttributeNames(MainWindow.clusterName);
            reloadAttInComboBox();
            //reloadAttTypeOfComboBox();
        }

        private void implied_from_to_b_Click(object sender, RoutedEventArgs e)
        {
            if (att_name_cb.Text == null)
            {
                MessageBox.Show("Missing attribute name...", "Error", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            else if (att_name_cb.Text.Trim().Equals(""))
            {
                MessageBox.Show("Missing attribute name...", "Error", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            else if (attributeAlreadyExist() == true)
            {
                MessageBox.Show("Attribute Name duplicate !", "Error", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            else if (allPrimaryCompsSelected() == false)
            {
                MessageBox.Show("unchecked property!", "Error", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            if (source_attribute == null)
            {
                source_attribute = new Attribute();
                source_attribute.clusterName = MainWindow.clusterName;
            }

            //string att_n = att_name_cb.Text;

            string att_n = null;
            if (att_name_cb.SelectedItem != null)
            {
                att_n = att_name_cb.SelectedItem.ToString();
            }
            else
            {
                att_n = att_name_cb.Text;
            }
            //att_n = att_name_cb.Text;

            //if (att_n == null || att_n.Equals(""))
            //{
            //    att_n = att_name_cb.SelectedItem.ToString();
            //}

            att_n = att_n.Trim();
            att_n = att_n.TrimEnd('\n');
            att_n = att_n.TrimEnd('\r');
                        
            string att_n_value = null;
            ComboBoxItem cbi = (ComboBoxItem)attributeValue_cb.SelectedItem;
            att_n_value = (string)cbi.Content;

            att_n_value = att_n_value.Trim();
            att_n_value = att_n_value.TrimEnd('\n');
            att_n_value = att_n_value.TrimEnd('\r');

            string att_n_obfuscation = null;
            ComboBoxItem cbo = (ComboBoxItem)obfuscation_level_cb.SelectedItem;
            if (cbo != null)
            {
                att_n_obfuscation = (string)cbo.Content;

                att_n_obfuscation = att_n_obfuscation.Trim();
                att_n_obfuscation = att_n_obfuscation.TrimEnd('\n');
                att_n_obfuscation = att_n_obfuscation.TrimEnd('\r');
            }            

            string description = att_description.Text;
            description = description.TrimEnd('\n');
            description = description.TrimEnd('\r');

            string literal_t = "";
            if (string_l.IsChecked == true)
            {
                literal_t = "[string]";
            }
            else if (numeric_l.IsChecked == true)
            {
                literal_t = "[numeric]";
            }
            else if (boolean_l.IsChecked == true)
            {
                literal_t = "[boolean]";
            }

            string category_t = "";
            if (categoryAgent.IsChecked == true)
            {
                category_t = "agentAttribute";
            }
            else if (categoryEnvironmental.IsChecked == true)
            {
                category_t = "environmentalAttribute";
            }
            else if (categoryRegulatory.IsChecked == true)
            {
                category_t = "regulatoryAttribute";
            }

            //bool isPrivate_a;
            //if (yes_p_rd.IsChecked == true)
            //{
            //    isPrivate_a = true;
            //}
            //else
            //{
            //    isPrivate_a = false;
            //}

            //bool personallyIdentifiable_a;
            //if (per_id_rd_y.IsChecked == true)
            //{
            //    personallyIdentifiable_a = true;
            //}
            //else
            //{
            //    personallyIdentifiable_a = false;
            //}

            att_name_cb.IsEnabled = false;
            //att_description.IsEnabled = false;

            source_attribute.name = att_n;
            source_attribute.description = description;
            source_attribute.literalType = literal_t;
            //source_attribute.isPrivate = isPrivate_a;
            //source_attribute.personallyIdentifiable = personallyIdentifiable_a;
            source_attribute.category = category_t;

            if (att_n_value.Equals("veryLow"))
            {
                source_attribute.sensitivityLevel = Attribute.Sensitivity.veryLow;
            }
            else if (att_n_value.Equals("low"))
            {
                source_attribute.sensitivityLevel = Attribute.Sensitivity.low;
            }
            else if (att_n_value.Equals("medium"))
            {
                source_attribute.sensitivityLevel = Attribute.Sensitivity.medium;
            }
            else if (att_n_value.Equals("high"))
            {
                source_attribute.sensitivityLevel = Attribute.Sensitivity.high;
            }
            else if (att_n_value.Equals("veryHigh"))
            {
                source_attribute.sensitivityLevel = Attribute.Sensitivity.veryHigh;
            }
            //source_attribute.attributeValue = att_n_value;

            if (att_n_obfuscation.Equals("AccuratePrecise"))
            {
                source_attribute.obfuscationLevel = Attribute.Obfuscation.AccuratePrecise;
            }
            else if (att_n_obfuscation.Equals("AccurateImprecise"))
            {
                source_attribute.obfuscationLevel = Attribute.Obfuscation.AccurateImprecise;
            }
            else if (att_n_obfuscation.Equals("InaccuratePrecise"))
            {
                source_attribute.obfuscationLevel = Attribute.Obfuscation.InaccuratePrecise;
            }
            else if (att_n_obfuscation.Equals("InccurateImprecise"))
            {
                source_attribute.obfuscationLevel = Attribute.Obfuscation.InccurateImprecise;
            }

            MisUseAnObjectsDB.addAttributeDB(source_attribute, MainWindow.clusterName);//intermediary attribute addition
           
            //att_name_cb.IsEnabled = false;
            //att_name_cb.IsEditable = false;
            if (containedimplications == null)
            {
                containedimplications = new List<string>();
            }
            if (containedaggregations == null)
            {
                containedaggregations = new List<string>();
            }
            //AddImpliedFromToAttributeWindow aiftaw = new AddImpliedFromToAttributeWindow(this, source_attribute);
            //aiftaw.Title = "Implied attributes properties: (" + source_attribute.name + ")";
            //aiftaw.Owner = (Window)this.Parent;
            //aiftaw.ShowDialog();
        }

        private void ok_actor_att_b_Click(object sender, RoutedEventArgs e)
        {
            if (att_name_cb.Text == null)
            {
                MessageBox.Show("Missing attribute name...", "Error", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            else if (att_name_cb.Text.Trim().Equals(""))
            {
                MessageBox.Show("Missing attribute name...", "Error", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            else if (attributeAlreadyExist() == true)
            {
                MessageBox.Show("Attribute Name duplicate !", "Error", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            else if (allPrimaryCompsSelected() == false)
            {
                MessageBox.Show("unchecked property!", "Error", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }


            if (source_attribute == null)
            {
                source_attribute = new Attribute();
                source_attribute.clusterName = MainWindow.clusterName;
            }

            //string att_n = att_name_cb.Text;

            string att_n = null;
            if (att_name_cb.SelectedItem != null)
            {
                att_n = att_name_cb.SelectedItem.ToString();
            }
            else
            {
                att_n = att_name_cb.Text;
            }

            //att_n = att_name_cb.Text;

            //if (att_n == null || att_n.Equals(""))
            //{
            //    att_n = att_name_cb.SelectedItem.ToString();
            //}

            att_n = att_n.Trim();
            att_n = att_n.TrimEnd('\n');
            att_n = att_n.TrimEnd('\r');

            string att_n_value = null;
            ComboBoxItem cbi = (ComboBoxItem)attributeValue_cb.SelectedItem;

            if (cbi != null)
            {
                att_n_value = (string)cbi.Content;

                att_n_value = att_n_value.Trim();
                att_n_value = att_n_value.TrimEnd('\n');
                att_n_value = att_n_value.TrimEnd('\r');
            }

            string att_n_obfuscation = null;
            ComboBoxItem cbo = (ComboBoxItem)obfuscation_level_cb.SelectedItem;
            if (cbo != null)
            {
                att_n_obfuscation = (string)cbo.Content;

                att_n_obfuscation = att_n_obfuscation.Trim();
                att_n_obfuscation = att_n_obfuscation.TrimEnd('\n');
                att_n_obfuscation = att_n_obfuscation.TrimEnd('\r');            
            }
            
            string description = att_description.Text;
            description = description.TrimEnd('\n');
            description = description.TrimEnd('\r');

            string literal_t = "";
            if (string_l.IsChecked == true)
            {
                literal_t = "[string]";
            }
            else if (numeric_l.IsChecked == true)
            {
                literal_t = "[numeric]";
            }
            else if (boolean_l.IsChecked == true)
            {
                literal_t = "[boolean]";
            }

            string category_t = "";
            if (categoryAgent.IsChecked == true)
            {
                category_t = "agentAttribute";
            }
            else if (categoryEnvironmental.IsChecked == true)
            {
                category_t = "environmentalAttribute";
            }
            else if (categoryRegulatory.IsChecked == true)
            {
                category_t = "regulatoryAttribute";
            }

            //bool isPrivate_a;
            //if (yes_p_rd.IsChecked == true)
            //{
            //    isPrivate_a = true;
            //}
            //else
            //{
            //    isPrivate_a = false;
            //}

            //bool personallyIdentifiable_a;
            //if (per_id_rd_y.IsChecked == true)
            //{
            //    personallyIdentifiable_a = true;
            //}
            //else
            //{
            //    personallyIdentifiable_a = false;
            //}
            source_attribute.name = att_n;
            source_attribute.description = description;
            source_attribute.literalType = literal_t;
            //source_attribute.isPrivate = isPrivate_a;
            //source_attribute.personallyIdentifiable = personallyIdentifiable_a;
            source_attribute.category = category_t;
           
            if (att_n_value.Equals("veryLow"))
            {
                source_attribute.sensitivityLevel = Attribute.Sensitivity.veryLow;
            }
            else if (att_n_value.Equals("low"))
            {
                source_attribute.sensitivityLevel = Attribute.Sensitivity.low;
            }
            else if (att_n_value.Equals("medium"))
            {
                source_attribute.sensitivityLevel = Attribute.Sensitivity.medium;
            }
            else if (att_n_value.Equals("high"))
            {
                source_attribute.sensitivityLevel = Attribute.Sensitivity.high;
            }
            else if (att_n_value.Equals("veryHigh"))
            {
                source_attribute.sensitivityLevel = Attribute.Sensitivity.veryHigh;
            }
            //source_attribute.attributeValue = att_n_value;

            if (att_n_obfuscation.Equals("AccuratePrecise"))
            {
                source_attribute.obfuscationLevel = Attribute.Obfuscation.AccuratePrecise;
            }
            else if (att_n_obfuscation.Equals("AccurateImprecise"))
            {
                source_attribute.obfuscationLevel = Attribute.Obfuscation.AccurateImprecise;
            }
            else if (att_n_obfuscation.Equals("InaccuratePrecise"))
            {
                source_attribute.obfuscationLevel = Attribute.Obfuscation.InaccuratePrecise;
            }
            else if (att_n_obfuscation.Equals("InccurateImprecise"))
            {
                source_attribute.obfuscationLevel = Attribute.Obfuscation.InccurateImprecise;
            }

            MisUseAnObjectsDB.addAttributeDB(source_attribute, MainWindow.clusterName);//intermediary attribute addition

            Image del = new Image();
            //del.Source = new BitmapImage(new Uri(@"images\delete.png", UriKind.RelativeOrAbsolute));
            del.Height = 6;
            del.Width = 6;

            Button del_b = new Button();
            del_b.Tag = source_attribute;
            del_b.Background = Brushes.WhiteSmoke;
            del_b.Content = del;
            del_b.AddHandler(Button.ClickEvent, new RoutedEventHandler(del_b_Click));

            InlineUIContainer myInlineUIContainer = new InlineUIContainer();
            myInlineUIContainer.Child = del_b;

            TableRow tr = new TableRow();
            tr.Tag = source_attribute;
            Paragraph p1 = new Paragraph(myInlineUIContainer);
            p1.FontSize = 10;
            p1.FontWeight = FontWeights.Light;
            tr.Cells.Add(new TableCell(p1));

            string att_name = source_attribute.name;
            if (source_attribute.personallyIdentifiable)
            {
                att_name = att_name + "(PI)";
            }

            Paragraph p2 = new Paragraph(new Run(att_name));
            p2.FontSize = 10;
            p2.FontWeight = FontWeights.Light;
            tr.Cells.Add(new TableCell(p2));
            
            Paragraph p3 = new Paragraph(new Run(source_attribute.isPrivate.ToString()));
            p3.FontSize = 10;
            p3.FontWeight = FontWeights.Light;
            tr.Cells.Add(new TableCell(p3));

            Paragraph p4 = new Paragraph();
            Paragraph p5 = new Paragraph();
                        
            Attribute iter = source_attribute;            

            //add bi-directional (symmetry) items to implied_from_listBox
            if (iter != null && iter.symmetry.Count > 0)
            {
                X(iter, p4, p5);
                Y(iter, p4, p5);
                Z(iter, p4, p5);
            }
            if (iter != null && iter.symmetry_inv.Count > 0)
            {
                XInv(iter, p4, p5);
                YInv(iter, p4, p5);
                ZInv(iter, p4, p5);
            }

            //add uni-directional (X->Y) items to implied_from_listBox
            if (iter != null && iter.implied_to.Count > 0)
            {
                X(iter, p4, p5);
                Y(iter, p4, p5);
                Z(iter, p4, p5);
            }
            if(iter != null && iter.implied_to_inv.Count>0)
            {
                XInv(iter, p4, p5);
                YInv(iter, p4, p5);
                ZInv(iter, p4, p5);
            }

            //add uni-directional (Y->X) items to implied_from_listBox
            if (iter != null && iter.implied_from.Count > 0)
            {
                X(iter, p4, p5);
                Y(iter, p4, p5);
                Z(iter, p4, p5);
            }
            if (iter != null && iter.implied_from_inv.Count > 0)
            {
                XInv(iter, p4, p5);
                YInv(iter, p4, p5);
                ZInv(iter, p4, p5);
            }

            p4.FontSize = 10;
            p4.FontWeight = FontWeights.Light;
            tr.Cells.Add(new TableCell(p4));
            
            //aggregations            
            p5.FontSize = 10;
            p5.FontWeight = FontWeights.Light;
            tr.Cells.Add(new TableCell(p5));

            if (aaw_ != null)
            {
                MisUseAnObjectsDB.addAttributeDB(source_attribute, MainWindow.clusterName);
                aaw_.addActorAttributesTable(source_attribute);
            }

            if (ci_ != null)
            {
                MisUseAnObjectsDB.addAttributeDB(source_attribute, MainWindow.clusterName);
                ci_.loadDomainAttributes();
            }
            if (eew_ != null)
            {
                MisUseAnObjectsDB.addAttributeDB(source_attribute, MainWindow.clusterName);
                eew_.loadDomainAttributes();
            }
            //close
            this.Close();
        }

        private void X(Attribute iter, Paragraph p4, Paragraph p5)
        {            
            foreach (Attribute impatt in iter.implied_from)
            {
                if (!iter.name.Equals(impatt.name))
                {
                    string s_str = impatt.name;
                    if (impatt.isPrivate)
                    {
                        s_str = s_str + "(P*)";
                    }
                    if (impatt.personallyIdentifiable)
                    {
                        s_str = s_str + "(PI)";
                    }
                    s_str = s_str + " → " + iter.name;
                    if (iter.isPrivate)
                    {
                        s_str = s_str + "(P*)";
                    }
                    if (iter.personallyIdentifiable)
                    {
                        s_str = s_str + "(PI)";
                    }
                    bool contained = containInPara(p4, s_str);
                    if (contained == false)
                    {
                        p4.Inlines.Add(new Run(s_str));
                        p4.Inlines.Add(new LineBreak());
                    }

                    MisUseAnObjectsDB.loadAggregateAttributes(iter, MainWindow.clusterName);
                    List<string> reviewedAggregates = new List<string>();
                    foreach (string ss in iter.aggregation_statements)
                    {
                        if (ss.Length > 0)
                        {
                            bool contained_ = false;
                            foreach (string a_s in reviewedAggregates)
                            {
                                if (a_s.Equals(ss))
                                {
                                    contained_ = true;
                                    break;
                                }
                            }
                            if (contained_ == false)
                            {
                                reviewedAggregates.Add(ss);
                                p5.Inlines.Add(new Run(ss));
                                p5.Inlines.Add(new LineBreak());
                            }
                        }                   
                    }
                    MisUseAnObjectsDB.loadAggregateAttributes(impatt, MainWindow.clusterName);
                    reviewedAggregates = new List<string>();
                    foreach (string ss in impatt.aggregation_statements)
                    {
                        if (ss.Length > 0)
                        {
                            bool contained_ = false;
                            foreach (string a_s in reviewedAggregates)
                            {
                                if (a_s.Equals(ss))
                                {
                                    contained_ = true;
                                    break;
                                }
                            }
                            if (contained_ == false)
                            {
                                reviewedAggregates.Add(ss);
                                p5.Inlines.Add(new Run(ss));
                                p5.Inlines.Add(new LineBreak());
                            }
                        }                    
                    }

                    if (impatt.implied_from.Count > 0)
                    {
                        iter = impatt;
                        X(iter, p4, p5);
                    }
                    if (impatt.symmetry.Count > 0)
                    {
                        iter = impatt;
                        Y(iter, p4, p5);
                    }
                    if (impatt.implied_to.Count > 0)
                    {
                        iter = impatt;
                        Z(iter, p4, p5);
                    }

                    if (impatt.implied_from_inv.Count > 0)
                    {
                        iter = impatt;
                        XInv(iter, p4, p5);
                    }
                    if (impatt.symmetry_inv.Count > 0)
                    {
                        iter = impatt;
                        YInv(iter, p4, p5);
                    }
                    if (impatt.implied_to_inv.Count > 0)
                    {
                        iter = impatt;
                        ZInv(iter, p4, p5);
                    }
                }

            }
        }

        private void XInv(Attribute iter, Paragraph p4, Paragraph p5)
        {
            foreach (Attribute impatt in iter.implied_from_inv)
            {
                if (!iter.name.Equals(impatt.name))
                {
                    string s_str = iter.name;
                    if (iter.isPrivate)
                    {
                        s_str = s_str + "(P*)";
                    }
                    if (iter.personallyIdentifiable)
                    {
                        s_str = s_str + "(PI)";
                    }
                    s_str = s_str + " → " + impatt.name;
                    if (impatt.isPrivate)
                    {
                        s_str = s_str + "(P*)";
                    }
                    if (impatt.personallyIdentifiable)
                    {
                        s_str = s_str + "(PI)";
                    }
                    bool contained = containInPara(p4, s_str);
                    if (contained == false)
                    {
                        p4.Inlines.Add(new Run(s_str));
                        p4.Inlines.Add(new LineBreak());
                    }

                    MisUseAnObjectsDB.loadAggregateAttributes(iter, MainWindow.clusterName);
                    List<string> reviewedAggregates = new List<string>();
                    foreach (string ss in iter.aggregation_statements)
                    {
                        if (ss.Length > 0)
                        {
                            bool contained_ = false;
                            foreach (string a_s in reviewedAggregates)
                            {
                                if (a_s.Equals(ss))
                                {
                                    contained_ = true;
                                    break;
                                }
                            }
                            if (contained_ == false)
                            {
                                reviewedAggregates.Add(ss);
                                p5.Inlines.Add(new Run(ss));
                                p5.Inlines.Add(new LineBreak());
                            }
                        }
                    }
                    MisUseAnObjectsDB.loadAggregateAttributes(impatt, MainWindow.clusterName);
                    reviewedAggregates = new List<string>();
                    foreach (string ss in impatt.aggregation_statements)
                    {
                        if (ss.Length > 0)
                        {
                            bool contained_ = false;
                            foreach (string a_s in reviewedAggregates)
                            {
                                if (a_s.Equals(ss))
                                {
                                    contained_ = true;
                                    break;
                                }
                            }
                            if (contained_ == false)
                            {
                                reviewedAggregates.Add(ss);
                                p5.Inlines.Add(new Run(ss));
                                p5.Inlines.Add(new LineBreak());
                            }
                        }
                    }

                    if (impatt.implied_from.Count > 0)
                    {
                        iter = impatt;
                        X(iter, p4, p5);
                    }
                    if (impatt.symmetry.Count > 0)
                    {
                        iter = impatt;
                        Y(iter, p4, p5);
                    }
                    if (impatt.implied_to.Count > 0)
                    {
                        iter = impatt;
                        Z(iter, p4, p5);
                    }

                    if (impatt.implied_from_inv.Count > 0)
                    {
                        iter = impatt;
                        XInv(iter, p4, p5);
                    }
                    if (impatt.symmetry_inv.Count > 0)
                    {
                        iter = impatt;
                        YInv(iter, p4, p5);
                    }
                    if (impatt.implied_to_inv.Count > 0)
                    {
                        iter = impatt;
                        ZInv(iter, p4, p5);
                    }
                }

            }
        }

        private void Y(Attribute iter, Paragraph p4, Paragraph p5)
        {
            foreach (Attribute impatt in iter.symmetry)
            {
                if (!iter.name.Equals(impatt.name))
                {
                    string s_str = iter.name;
                    if (iter.isPrivate)
                    {
                        s_str = s_str + "(P*)";
                    }
                    if (iter.personallyIdentifiable)
                    {
                        s_str = s_str + "(PI)";
                    }
                    s_str = s_str + " ↔ " + impatt.name;
                    if (impatt.isPrivate)
                    {
                        s_str = s_str + "(P*)";
                    }
                    if (impatt.personallyIdentifiable)
                    {
                        s_str = s_str + "(PI)";
                    }
                    bool contained = containInPara(p4, s_str);
                    if (contained == false)
                    {
                        p4.Inlines.Add(new Run(s_str));
                        p4.Inlines.Add(new LineBreak());
                    }

                    MisUseAnObjectsDB.loadAggregateAttributes(iter, MainWindow.clusterName);
                    List<string> reviewedAggregates = new List<string>();
                    foreach (string ss in iter.aggregation_statements)
                    {
                        if (ss.Length > 0)
                        {
                            bool contained_ = false;
                            foreach (string a_s in reviewedAggregates)
                            {
                                if (a_s.Equals(ss))
                                {
                                    contained_ = true;
                                    break;
                                }
                            }
                            if (contained_ == false)
                            {
                                reviewedAggregates.Add(ss);
                                p5.Inlines.Add(new Run(ss));
                                p5.Inlines.Add(new LineBreak());
                            }
                        }
                    }
                    MisUseAnObjectsDB.loadAggregateAttributes(impatt, MainWindow.clusterName);
                    reviewedAggregates = new List<string>();
                    foreach (string ss in impatt.aggregation_statements)
                    {
                        if (ss.Length > 0)
                        {
                            bool contained_ = false;
                            foreach (string a_s in reviewedAggregates)
                            {
                                if (a_s.Equals(ss))
                                {
                                    contained_ = true;
                                    break;
                                }
                            }
                            if (contained_ == false)
                            {
                                reviewedAggregates.Add(ss);
                                p5.Inlines.Add(new Run(ss));
                                p5.Inlines.Add(new LineBreak());
                            }
                        }
                    }

                    if (impatt.implied_from.Count > 0)
                    {
                        iter = impatt;
                        X(iter, p4, p5);
                    }
                    if (impatt.symmetry.Count > 0)
                    {
                        iter = impatt;
                        Y(iter, p4, p5);
                    }
                    if (impatt.implied_to.Count > 0)
                    {
                        iter = impatt;
                        Z(iter, p4, p5);
                    }

                    if (impatt.implied_from_inv.Count > 0)
                    {
                        iter = impatt;
                        XInv(iter, p4, p5);
                    }
                    if (impatt.symmetry_inv.Count > 0)
                    {
                        iter = impatt;
                        YInv(iter, p4, p5);
                    }
                    if (impatt.implied_to_inv.Count > 0)
                    {
                        iter = impatt;
                        ZInv(iter, p4, p5);
                    }
                }

            }
        }

        private void YInv(Attribute iter, Paragraph p4, Paragraph p5)
        {
            foreach (Attribute impatt in iter.symmetry_inv)
            {
                if (!iter.name.Equals(impatt.name))
                {
                   string s_str = impatt.name;
                    if (impatt.isPrivate)
                    {
                        s_str = s_str + "(P*)";
                    }
                    if (impatt.personallyIdentifiable)
                    {
                        s_str = s_str + "(PI)";
                    }
                    s_str = s_str + " ↔ " + iter.name;
                    if (iter.isPrivate)
                    {
                        s_str = s_str + "(P*)";
                    }
                    if (iter.personallyIdentifiable)
                    {
                        s_str = s_str + "(PI)";
                    }
                    bool contained = containInPara(p4, s_str);
                    if (contained == false)
                    {
                        p4.Inlines.Add(new Run(s_str));
                        p4.Inlines.Add(new LineBreak());
                    }

                    MisUseAnObjectsDB.loadAggregateAttributes(iter, MainWindow.clusterName);
                    List<string> reviewedAggregates = new List<string>();
                    foreach (string ss in iter.aggregation_statements)
                    {
                        if (ss.Length > 0)
                        {
                            bool contained_ = false;
                            foreach (string a_s in reviewedAggregates)
                            {
                                if (a_s.Equals(ss))
                                {
                                    contained_ = true;
                                    break;
                                }
                            }
                            if (contained_ == false)
                            {
                                reviewedAggregates.Add(ss);
                                p5.Inlines.Add(new Run(ss));
                                p5.Inlines.Add(new LineBreak());
                            }
                        }
                    }
                    MisUseAnObjectsDB.loadAggregateAttributes(impatt, MainWindow.clusterName);
                    reviewedAggregates = new List<string>();
                    foreach (string ss in impatt.aggregation_statements)
                    {
                        if (ss.Length > 0)
                        {
                            bool contained_ = false;
                            foreach (string a_s in reviewedAggregates)
                            {
                                if (a_s.Equals(ss))
                                {
                                    contained_ = true;
                                    break;
                                }
                            }
                            if (contained_ == false)
                            {
                                reviewedAggregates.Add(ss);
                                p5.Inlines.Add(new Run(ss));
                                p5.Inlines.Add(new LineBreak());
                            }
                        }
                    }

                    if (impatt.implied_from.Count > 0)
                    {
                        iter = impatt;
                        X(iter, p4, p5);
                    }
                    if (impatt.symmetry.Count > 0)
                    {
                        iter = impatt;
                        Y(iter, p4, p5);
                    }
                    if (impatt.implied_to.Count > 0)
                    {
                        iter = impatt;
                        Z(iter, p4, p5);
                    }

                    if (impatt.implied_from_inv.Count > 0)
                    {
                        iter = impatt;
                        XInv(iter, p4, p5);
                    }
                    if (impatt.symmetry_inv.Count > 0)
                    {
                        iter = impatt;
                        YInv(iter, p4, p5);
                    }
                    if (impatt.implied_to_inv.Count > 0)
                    {
                        iter = impatt;
                        ZInv(iter, p4, p5);
                    }
                }
 
            }
        }

        private void Z(Attribute iter, Paragraph p4, Paragraph p5)
        {
            foreach (Attribute impatt in iter.implied_to)
            {
                if (!iter.name.Equals(impatt.name))
                {
                    string s_str = iter.name;
                    if (iter.isPrivate)
                    {
                        s_str = s_str + "(P*)";
                    }
                    if (iter.personallyIdentifiable)
                    {
                        s_str = s_str + "(PI)";
                    }
                    s_str = s_str + " → " + impatt.name;
                    if (impatt.isPrivate)
                    {
                        s_str = s_str + "(P*)";
                    }
                    if (impatt.personallyIdentifiable)
                    {
                        s_str = s_str + "(PI)";
                    }
                    bool contained = containInPara(p4, s_str);
                    if (contained == false)
                    {
                        p4.Inlines.Add(new Run(s_str));
                        p4.Inlines.Add(new LineBreak());
                    }

                    MisUseAnObjectsDB.loadAggregateAttributes(iter, MainWindow.clusterName);
                    List<string> reviewedAggregates = new List<string>();
                    foreach (string ss in iter.aggregation_statements)
                    {
                        if (ss.Length > 0)
                        {
                            bool contained_ = false;
                            foreach (string a_s in reviewedAggregates)
                            {
                                if (a_s.Equals(ss))
                                {
                                    contained_ = true;
                                    break;
                                }
                            }
                            if (contained_ == false)
                            {
                                reviewedAggregates.Add(ss);
                                p5.Inlines.Add(new Run(ss));
                                p5.Inlines.Add(new LineBreak());
                            }
                        }
                    }
                    MisUseAnObjectsDB.loadAggregateAttributes(impatt, MainWindow.clusterName);
                    reviewedAggregates = new List<string>();
                    foreach (string ss in impatt.aggregation_statements)
                    {
                        if (ss.Length > 0)
                        {
                            bool contained_ = false;
                            foreach (string a_s in reviewedAggregates)
                            {
                                if (a_s.Equals(ss))
                                {
                                    contained_ = true;
                                    break;
                                }
                            }
                            if (contained_ == false)
                            {
                                reviewedAggregates.Add(ss);
                                p5.Inlines.Add(new Run(ss));
                                p5.Inlines.Add(new LineBreak());
                            }
                        }
                    }

                    if (impatt.implied_from.Count > 0)
                    {
                        iter = impatt;
                        X(iter, p4, p5);
                    }
                    if (impatt.symmetry.Count > 0)
                    {
                        iter = impatt;
                        Y(iter, p4, p5);
                    }
                    if (impatt.implied_to.Count > 0)
                    {
                        iter = impatt;
                        Z(iter, p4, p5);
                    }

                    if (impatt.implied_from_inv.Count > 0)
                    {
                        iter = impatt;
                        XInv(iter, p4, p5);
                    }
                    if (impatt.symmetry_inv.Count > 0)
                    {
                        iter = impatt;
                        YInv(iter, p4, p5);
                    }
                    if (impatt.implied_to_inv.Count > 0)
                    {
                        iter = impatt;
                        ZInv(iter, p4, p5);
                    }
                }

            }
            
        }

        private void ZInv(Attribute iter, Paragraph p4, Paragraph p5)
        {            
            foreach (Attribute impatt in iter.implied_to_inv)
            {
                if (!iter.name.Equals(impatt.name))
                {
                    string s_str = impatt.name;
                    if (impatt.isPrivate)
                    {
                        s_str = s_str + "(P*)";
                    }
                    if (impatt.personallyIdentifiable)
                    {
                        s_str = s_str + "(PI)";
                    }
                    s_str = s_str + " → " + iter.name;
                    if (iter.isPrivate)
                    {
                        s_str = s_str + "(P*)";
                    }
                    if (iter.personallyIdentifiable)
                    {
                        s_str = s_str + "(PI)";
                    }
                    bool contained = containInPara(p4, s_str);
                    if (contained == false)
                    {
                        p4.Inlines.Add(new Run(s_str));
                        p4.Inlines.Add(new LineBreak());
                    }

                    MisUseAnObjectsDB.loadAggregateAttributes(iter, MainWindow.clusterName);
                    List<string> reviewedAggregates = new List<string>();
                    foreach (string ss in iter.aggregation_statements)
                    {
                        if (ss.Length > 0)
                        {
                            bool contained_ = false;
                            foreach (string a_s in reviewedAggregates)
                            {
                                if (a_s.Equals(ss))
                                {
                                    contained_ = true;
                                    break;
                                }
                            }
                            if (contained_ == false)
                            {
                                reviewedAggregates.Add(ss);
                                p5.Inlines.Add(new Run(ss));
                                p5.Inlines.Add(new LineBreak());
                            }
                        }
                    }
                    MisUseAnObjectsDB.loadAggregateAttributes(impatt, MainWindow.clusterName);
                    reviewedAggregates = new List<string>();
                    foreach (string ss in impatt.aggregation_statements)
                    {
                        if (ss.Length > 0)
                        {
                            bool contained_ = false;
                            foreach (string a_s in reviewedAggregates)
                            {
                                if (a_s.Equals(ss))
                                {
                                    contained_ = true;
                                    break;
                                }
                            }
                            if (contained_ == false)
                            {
                                reviewedAggregates.Add(ss);
                                p5.Inlines.Add(new Run(ss));
                                p5.Inlines.Add(new LineBreak());
                            }
                        }
                    }

                    if (impatt.implied_from.Count > 0)
                    {
                        iter = impatt;
                        X(iter, p4, p5);
                    }
                    if (impatt.symmetry.Count > 0)
                    {
                        iter = impatt;
                        Y(iter, p4, p5);
                    }
                    if (impatt.implied_to.Count > 0)
                    {
                        iter = impatt;
                        Z(iter, p4, p5);
                    }

                    if (impatt.implied_from_inv.Count > 0)
                    {
                        iter = impatt;
                        XInv(iter, p4, p5);
                    }
                    if (impatt.symmetry_inv.Count > 0)
                    {
                        iter = impatt;
                        YInv(iter, p4, p5);
                    }
                    if (impatt.implied_to_inv.Count > 0)
                    {
                        iter = impatt;
                        ZInv(iter, p4, p5);
                    }
                }

            }
        }

        private void Zthis(Attribute iter)
        {
            foreach (Attribute impatt in iter.implied_to)
            {
                if (!iter.name.Equals(impatt.name))
                {
                    string s_str = iter.name + " → " + impatt.name;
                    //bool contained = implied_from_listBox.Items.Contains(s_str);

                    bool contained = false;
                    foreach (string implication in containedimplications)
                    {
                        if (implication.Equals(s_str))
                        {
                            contained = true;
                            break;
                        }
                    }
                    if (contained == false)
                    {
                        containedimplications.Add(s_str);

                        CheckBox cb = new CheckBox();
                        cb.Tag = s_str;
                        cb.Content = s_str;
                        cb.AddHandler(CheckBox.CheckedEvent, new RoutedEventHandler(del_impliedTo_Checked));
                        //implied_from_listBox.Items.Add(cb);
                    }                

                    MisUseAnObjectsDB.loadAggregateAttributes(iter, MainWindow.clusterName);
                    foreach (string ss in iter.aggregation_statements)
                    {
                        if (ss.Length > 0)
                        {
                            bool contained_ = false;
                            foreach (string aggregation in containedaggregations)
                            {
                                if (aggregation.Equals(ss))
                                {
                                    contained_ = true;
                                    break;
                                }
                            }
                            if (contained_ == false)
                            {
                                containedaggregations.Add(ss);

                                CheckBox cb = new CheckBox();
                                cb.Tag = ss;
                                cb.Content = ss;
                                cb.AddHandler(CheckBox.CheckedEvent, new RoutedEventHandler(del_aggregation_Checked));
                                att_aggregation_listBox.Items.Add(cb);
                            }
                        }

                    }
                    MisUseAnObjectsDB.loadAggregateAttributes(impatt, MainWindow.clusterName);
                    foreach (string ss in impatt.aggregation_statements)
                    {
                        if (ss.Length > 0)
                        {
                            bool contained_ = false;
                            foreach (string aggregation in containedaggregations)
                            {
                                if (aggregation.Equals(ss))
                                {
                                    contained_ = true;
                                    break;
                                }
                            }
                            if (contained_ == false)
                            {
                                containedaggregations.Add(ss);

                                CheckBox cb = new CheckBox();
                                cb.Tag = ss;
                                cb.Content = ss;
                                cb.AddHandler(CheckBox.CheckedEvent, new RoutedEventHandler(del_aggregation_Checked));
                                att_aggregation_listBox.Items.Add(cb);
                            }
                        }

                    }

                    if (impatt.implied_from.Count > 0)
                    {
                        iter = impatt;
                        Xthis(iter);
                    }
                    if (impatt.symmetry.Count > 0)
                    {
                        iter = impatt;
                        Ythis(iter);
                    }
                    if (impatt.implied_to.Count > 0)
                    {
                        iter = impatt;
                        Zthis(iter);
                    }

                    if (impatt.implied_from_inv.Count > 0)
                    {
                        iter = impatt;
                        XthisInv(iter);
                    }
                    if (impatt.symmetry_inv.Count > 0)
                    {
                        iter = impatt;
                        YthisInv(iter);
                    }
                    if (impatt.implied_to_inv.Count > 0)
                    {
                        iter = impatt;
                        ZthisInv(iter);
                    }
                }

            }
        }

        private void ZthisInv(Attribute iter)
        {
            foreach (Attribute impatt in iter.implied_to_inv)
            {
                if (!iter.name.Equals(impatt.name))
                {
                    string s_str = impatt.name + " → " + iter.name;
                    //bool contained = implied_from_listBox.Items.Contains(s_str);

                    bool contained = false;
                    foreach (string implication in containedimplications)
                    {
                        if (implication.Equals(s_str))
                        {
                            contained = true;
                            break;
                        }
                    }
                    if (contained == false)
                    {
                        containedimplications.Add(s_str);

                        CheckBox cb = new CheckBox();
                        cb.Tag = s_str;
                        cb.Content = s_str;
                        cb.AddHandler(CheckBox.CheckedEvent, new RoutedEventHandler(del_impliedTo_Checked));
                        //implied_from_listBox.Items.Add(cb);
                    }

                    MisUseAnObjectsDB.loadAggregateAttributes(iter, MainWindow.clusterName);
                    foreach (string ss in iter.aggregation_statements)
                    {
                        if (ss.Length > 0)
                        {
                            bool contained_ = false;
                            foreach (string aggregation in containedaggregations)
                            {
                                if (aggregation.Equals(ss))
                                {
                                    contained_ = true;
                                    break;
                                }
                            }
                            if (contained_ == false)
                            {
                                containedaggregations.Add(ss);

                                CheckBox cb = new CheckBox();
                                cb.Tag = ss;
                                cb.Content = ss;
                                cb.AddHandler(CheckBox.CheckedEvent, new RoutedEventHandler(del_aggregation_Checked));
                                att_aggregation_listBox.Items.Add(cb);
                            }
                        }

                    }
                    MisUseAnObjectsDB.loadAggregateAttributes(impatt, MainWindow.clusterName);
                    foreach (string ss in impatt.aggregation_statements)
                    {
                        if (ss.Length > 0)
                        {
                            bool contained_ = false;
                            foreach (string aggregation in containedaggregations)
                            {
                                if (aggregation.Equals(ss))
                                {
                                    contained_ = true;
                                    break;
                                }
                            }
                            if (contained_ == false)
                            {
                                containedaggregations.Add(ss);

                                CheckBox cb = new CheckBox();
                                cb.Tag = ss;
                                cb.Content = ss;
                                cb.AddHandler(CheckBox.CheckedEvent, new RoutedEventHandler(del_aggregation_Checked));
                                att_aggregation_listBox.Items.Add(cb);
                            }
                        }
                    }

                    if (impatt.implied_from.Count > 0)
                    {
                        iter = impatt;
                        Xthis(iter);
                    }
                    if (impatt.symmetry.Count > 0)
                    {
                        iter = impatt;
                        Ythis(iter);
                    }
                    if (impatt.implied_to.Count > 0)
                    {
                        iter = impatt;
                        Zthis(iter);
                    }

                    if (impatt.implied_from_inv.Count > 0)
                    {
                        iter = impatt;
                        XthisInv(iter);
                    }
                    if (impatt.symmetry_inv.Count > 0)
                    {
                        iter = impatt;
                        YthisInv(iter);
                    }
                    if (impatt.implied_to_inv.Count > 0)
                    {
                        iter = impatt;
                        ZthisInv(iter);
                    }
                }

            }
        }

        private void Ythis(Attribute iter)
        {
            foreach (Attribute impatt in iter.symmetry)
            {
                if (!iter.name.Equals(impatt.name))
                {
                    string s_str = iter.name + " ↔ " + impatt.name;

                    //bool contained = implied_from_listBox.Items.Contains(s_str);
                    bool contained = false;
                    foreach (string implication in containedimplications)
                    {
                        if (implication.Equals(s_str))
                        {
                            contained = true;
                            break;
                        }
                    }
                    if (contained == false)
                    {
                        containedimplications.Add(s_str);

                        CheckBox cb = new CheckBox();
                        cb.Tag = s_str;
                        cb.Content = s_str;
                        cb.AddHandler(CheckBox.CheckedEvent, new RoutedEventHandler(del_symmetry_Checked));
                        //implied_from_listBox.Items.Add(cb);
                    }
                
                    MisUseAnObjectsDB.loadAggregateAttributes(iter, MainWindow.clusterName);
                    foreach (string ss in iter.aggregation_statements)
                    {
                        if (ss.Length > 0)
                        {
                            bool contained_ = false;
                            foreach (string aggregation in containedaggregations)
                            {
                                if (aggregation.Equals(ss))
                                {
                                    contained_ = true;
                                    break;
                                }
                            }
                            if (contained_ == false)
                            {
                                containedaggregations.Add(ss);

                                CheckBox cb = new CheckBox();
                                cb.Tag = ss;
                                cb.Content = ss;
                                cb.AddHandler(CheckBox.CheckedEvent, new RoutedEventHandler(del_aggregation_Checked));
                                att_aggregation_listBox.Items.Add(cb);
                            }
                        }
                    }
                    MisUseAnObjectsDB.loadAggregateAttributes(impatt, MainWindow.clusterName);
                    foreach (string ss in impatt.aggregation_statements)
                    {
                        if (ss.Length > 0)
                        {
                            bool contained_ = false;
                            foreach (string aggregation in containedaggregations)
                            {
                                if (aggregation.Equals(ss))
                                {
                                    contained_ = true;
                                    break;
                                }
                            }
                            if (contained_ == false)
                            {
                                containedaggregations.Add(ss);

                                CheckBox cb = new CheckBox();
                                cb.Tag = ss;
                                cb.Content = ss;
                                cb.AddHandler(CheckBox.CheckedEvent, new RoutedEventHandler(del_aggregation_Checked));
                                att_aggregation_listBox.Items.Add(cb);
                            }
                        }
                    }
                
                    if (impatt.implied_from.Count > 0)
                    {
                        iter = impatt;
                        Xthis(iter);
                    }
                    if (impatt.symmetry.Count > 0)
                    {
                        iter = impatt;
                        Ythis(iter);
                    }
                    if (impatt.implied_to.Count > 0)
                    {
                        iter = impatt;
                        Zthis(iter);
                    }

                    if (impatt.implied_from_inv.Count > 0)
                    {
                        iter = impatt;
                        XthisInv(iter);
                    }
                    if (impatt.symmetry_inv.Count > 0)
                    {
                        iter = impatt;
                        YthisInv(iter);
                    }
                    if (impatt.implied_to_inv.Count > 0)
                    {
                        iter = impatt;
                        ZthisInv(iter);
                    }
                }

            }
        }

        private void YthisInv(Attribute iter)
        {
            foreach (Attribute impatt in iter.symmetry_inv)
            {
                if (!iter.name.Equals(impatt.name))
                {
                    string s_str = impatt.name + " ↔ " + iter.name;

                    //bool contained = implied_from_listBox.Items.Contains(s_str);
                    bool contained = false;
                    foreach (string implication in containedimplications)
                    {
                        if (implication.Equals(s_str))
                        {
                            contained = true;
                            break;
                        }
                    }
                    if (contained == false)
                    {
                        containedimplications.Add(s_str);

                        CheckBox cb = new CheckBox();
                        cb.Tag = s_str;
                        cb.Content = s_str;
                        cb.AddHandler(CheckBox.CheckedEvent, new RoutedEventHandler(del_symmetry_Checked));
                        //implied_from_listBox.Items.Add(cb);
                    }

                    MisUseAnObjectsDB.loadAggregateAttributes(iter, MainWindow.clusterName);
                    foreach (string ss in iter.aggregation_statements)
                    {
                        if (ss.Length > 0)
                        {
                            bool contained_ = false;
                            foreach (string aggregation in containedaggregations)
                            {
                                if (aggregation.Equals(ss))
                                {
                                    contained_ = true;
                                    break;
                                }
                            }
                            if (contained_ == false)
                            {
                                containedaggregations.Add(ss);

                                CheckBox cb = new CheckBox();
                                cb.Tag = ss;
                                cb.Content = ss;
                                cb.AddHandler(CheckBox.CheckedEvent, new RoutedEventHandler(del_aggregation_Checked));
                                att_aggregation_listBox.Items.Add(cb);
                            }
                        }

                    }
                    MisUseAnObjectsDB.loadAggregateAttributes(impatt, MainWindow.clusterName);
                    foreach (string ss in impatt.aggregation_statements)
                    {
                        if (ss.Length > 0)
                        {
                            bool contained_ = false;
                            foreach (string aggregation in containedaggregations)
                            {
                                if (aggregation.Equals(ss))
                                {
                                    contained_ = true;
                                    break;
                                }
                            }
                            if (contained_ == false)
                            {
                                containedaggregations.Add(ss);

                                CheckBox cb = new CheckBox();
                                cb.Tag = ss;
                                cb.Content = ss;
                                cb.AddHandler(CheckBox.CheckedEvent, new RoutedEventHandler(del_aggregation_Checked));
                                att_aggregation_listBox.Items.Add(cb);
                            }
                        }
                    }
                    if (impatt.implied_from.Count > 0)
                    {
                        iter = impatt;
                        Xthis(iter);
                    }
                    if (impatt.symmetry.Count > 0)
                    {
                        iter = impatt;
                        Ythis(iter);
                    }
                    if (impatt.implied_to.Count > 0)
                    {
                        iter = impatt;
                        Zthis(iter);
                    }

                    if (impatt.implied_from_inv.Count > 0)
                    {
                        iter = impatt;
                        XthisInv(iter);
                    }
                    if (impatt.symmetry_inv.Count > 0)
                    {
                        iter = impatt;
                        YthisInv(iter);
                    }
                    if (impatt.implied_to_inv.Count > 0)
                    {
                        iter = impatt;
                        ZthisInv(iter);
                    }
                }

            }
        }

        private void Xthis(Attribute iter)
        {
            foreach (Attribute impatt in iter.implied_from)
            {
                if (!iter.name.Equals(impatt.name))
                {
                    string s_str = impatt.name + " → " + iter.name;
                    //bool contained = implied_from_listBox.Items.Contains(s_str);
                    bool contained = false;
                    foreach (string implication in containedimplications)
                    {
                        if (implication.Equals(s_str))
                        {
                            contained = true;
                            break;
                        }
                    }
                    if (contained == false)
                    {
                        containedimplications.Add(s_str);

                        CheckBox cb = new CheckBox();
                        cb.Tag = s_str;
                        cb.Content = s_str;
                        cb.AddHandler(CheckBox.CheckedEvent, new RoutedEventHandler(del_impliedFrom_Checked));
                        //implied_from_listBox.Items.Add(cb);
                    }
                
                    MisUseAnObjectsDB.loadAggregateAttributes(iter, MainWindow.clusterName);
                    foreach (string ss in iter.aggregation_statements)
                    {
                        if (ss.Length > 0)
                        {
                            bool contained_ = false;
                            foreach (string aggregation in containedaggregations)
                            {
                                if (aggregation.Equals(ss))
                                {
                                    contained_ = true;
                                    break;
                                }
                            }
                            if (contained_ == false)
                            {
                                containedaggregations.Add(ss);

                                CheckBox cb = new CheckBox();
                                cb.Tag = ss;
                                cb.Content = ss;
                                cb.AddHandler(CheckBox.CheckedEvent, new RoutedEventHandler(del_aggregation_Checked));
                                att_aggregation_listBox.Items.Add(cb);
                            }
                        }
                    }
                    MisUseAnObjectsDB.loadAggregateAttributes(impatt, MainWindow.clusterName);
                    foreach (string ss in impatt.aggregation_statements)
                    {
                        if (ss.Length > 0)
                        {
                            bool contained_ = false;
                            foreach (string aggregation in containedaggregations)
                            {
                                if (aggregation.Equals(ss))
                                {
                                    contained_ = true;
                                    break;
                                }
                            }
                            if (contained_ == false)
                            {
                                containedaggregations.Add(ss);

                                CheckBox cb = new CheckBox();
                                cb.Tag = ss;
                                cb.Content = ss;
                                cb.AddHandler(CheckBox.CheckedEvent, new RoutedEventHandler(del_aggregation_Checked));
                                att_aggregation_listBox.Items.Add(cb);
                            }
                        }                   
                    }
                
                    if (impatt.implied_from.Count > 0)
                    {
                        iter = impatt;
                        Xthis(iter);
                    }
                    if (impatt.symmetry.Count > 0)
                    {
                        iter = impatt;
                        Ythis(iter);
                    }
                    if (impatt.implied_to.Count > 0)
                    {
                        iter = impatt;
                        Zthis(iter);
                    }

                    if (impatt.implied_from_inv.Count > 0)
                    {
                        iter = impatt;
                        XthisInv(iter);
                    }
                    if (impatt.symmetry_inv.Count > 0)
                    {
                        iter = impatt;
                        YthisInv(iter);
                    }
                    if (impatt.implied_to_inv.Count > 0)
                    {
                        iter = impatt;
                        ZthisInv(iter);
                    }
                }

            }
        }

        private void XthisInv(Attribute iter)
        {
            foreach (Attribute impatt in iter.implied_from_inv)
            {
                if (!iter.name.Equals(impatt.name))
                {
                    string s_str = iter.name + " → " + impatt.name;
                    //bool contained = implied_from_listBox.Items.Contains(s_str);
                    bool contained = false;
                    foreach (string implication in containedimplications)
                    {
                        if (implication.Equals(s_str))
                        {
                            contained = true;
                            break;
                        }
                    }
                    if (contained == false)
                    {
                        containedimplications.Add(s_str);

                        CheckBox cb = new CheckBox();
                        cb.Tag = s_str;
                        cb.Content = s_str;
                        cb.AddHandler(CheckBox.CheckedEvent, new RoutedEventHandler(del_impliedFrom_Checked));
                        //implied_from_listBox.Items.Add(cb);
                    }

                    MisUseAnObjectsDB.loadAggregateAttributes(iter, MainWindow.clusterName);
                    foreach (string ss in iter.aggregation_statements)
                    {
                        if (ss.Length > 0)
                        {
                            bool contained_ = false;
                            foreach (string aggregation in containedaggregations)
                            {
                                if (aggregation.Equals(ss))
                                {
                                    contained_ = true;
                                    break;
                                }
                            }
                            if (contained_ == false)
                            {
                                containedaggregations.Add(ss);

                                CheckBox cb = new CheckBox();
                                cb.Tag = ss;
                                cb.Content = ss;
                                cb.AddHandler(CheckBox.CheckedEvent, new RoutedEventHandler(del_aggregation_Checked));
                                att_aggregation_listBox.Items.Add(cb);
                            }
                        }
                    }
                    MisUseAnObjectsDB.loadAggregateAttributes(impatt, MainWindow.clusterName);
                    foreach (string ss in impatt.aggregation_statements)
                    {
                        if (ss.Length > 0)
                        {
                            bool contained_ = false;
                            foreach (string aggregation in containedaggregations)
                            {
                                if (aggregation.Equals(ss))
                                {
                                    contained_ = true;
                                    break;
                                }
                            }
                            if (contained_ == false)
                            {
                                containedaggregations.Add(ss);

                                CheckBox cb = new CheckBox();
                                cb.Tag = ss;
                                cb.Content = ss;
                                cb.AddHandler(CheckBox.CheckedEvent, new RoutedEventHandler(del_aggregation_Checked));
                                att_aggregation_listBox.Items.Add(cb);
                            }
                        }
                    }

                    if (impatt.implied_from.Count > 0)
                    {
                        iter = impatt;
                        Xthis(iter);
                    }
                    if (impatt.symmetry.Count > 0)
                    {
                        iter = impatt;
                        Ythis(iter);
                    }
                    if (impatt.implied_to.Count > 0)
                    {
                        iter = impatt;
                        Zthis(iter);
                    }

                    if (impatt.implied_from_inv.Count > 0)
                    {
                        iter = impatt;
                        XthisInv(iter);
                    }
                    if (impatt.symmetry_inv.Count > 0)
                    {
                        iter = impatt;
                        YthisInv(iter);
                    }
                    if (impatt.implied_to_inv.Count > 0)
                    {
                        iter = impatt;
                        ZthisInv(iter);
                    }
                }

            }
        }


        public void del_impliedTo_Checked(object sender, RoutedEventArgs e)
        {
            CheckBox d_cb = (CheckBox)sender;
            string tag_id = (string)d_cb.Tag;

            MessageBoxResult result = MessageBox.Show(this, "delete " + tag_id,
                            "Confirm delete", MessageBoxButton.YesNo,
                            MessageBoxImage.Information);

            if (result == MessageBoxResult.No)
            {
                d_cb.IsChecked = false;
            }
            else
            {
                string[] imp_atts = tag_id.Split('→');
                string att_name = imp_atts[0].Trim();
                string implied_to_att = imp_atts[1].Trim();

                bool deleted = false;
                for (int i = 0; i < source_attribute.implied_to.Count; i++)
                {
                    if (source_attribute.implied_to[i].name.Equals(implied_to_att))
                    {
                        source_attribute.implied_to.RemoveAt(i);
                        deleted = true;
                        break;
                    }
                }
                if (deleted == false)
                {
                    for (int i = 0; i < source_attribute.implied_to_inv.Count; i++)
                    {
                        if (source_attribute.implied_to_inv[i].name.Equals(implied_to_att))
                        {
                            source_attribute.implied_to_inv.RemoveAt(i);
                            break;
                        }
                    }
                }
                
                //MisUseAnObjectsDB.deleteImpliedToWithAttribute(att_name, implied_to_att, MainWindow.clusterName);
                reloadImpliedFromToList(source_attribute);
            }
        }

        public void del_aggregation_Checked(object sender, RoutedEventArgs e)
        {
            CheckBox d_cb = (CheckBox)sender;
            string tag_id = (string)d_cb.Tag;

            MessageBoxResult result = MessageBox.Show(this, "delete " + tag_id,
                            "Confirm delete", MessageBoxButton.YesNo,
                            MessageBoxImage.Information);

            if (result == MessageBoxResult.No)
            {
                d_cb.IsChecked = false;
            }
            else
            {
                for (int i = 0; i < source_attribute.aggregation_statements.Count; i++)
                {
                    if (source_attribute.aggregation_statements[i].Equals(tag_id))
                    {
                        source_attribute.aggregation_statements.RemoveAt(i);
                        break;
                    }
                }
                
                MisUseAnObjectsDB.deleteAggregationStatement(tag_id, MainWindow.clusterName);
                reloadAggregationList(source_attribute);
            }
        }
        
        public void del_symmetry_Checked(object sender, RoutedEventArgs e)
        {
            CheckBox d_cb = (CheckBox)sender;
            string tag_id = (string)d_cb.Tag;

            MessageBoxResult result = MessageBox.Show(this, "delete " + tag_id,
                            "Confirm delete", MessageBoxButton.YesNo,
                            MessageBoxImage.Information);

            if (result == MessageBoxResult.No)
            {
                d_cb.IsChecked = false;
            }
            else
            {
                string[] sym_atts = tag_id.Split('↔');
                string att_name = sym_atts[0].Trim();
                string symmetry_att = sym_atts[1].Trim();

                bool deleted = false;
                for (int i = 0; i < source_attribute.symmetry.Count; i++)
                {
                    if (source_attribute.symmetry[i].name.Equals(symmetry_att))
                    {
                        source_attribute.symmetry.RemoveAt(i);
                        deleted = true;
                        break;
                    }
                }
                if (deleted == false)
                {
                    for (int i = 0; i < source_attribute.symmetry_inv.Count; i++)
                    {
                        if (source_attribute.symmetry_inv[i].name.Equals(symmetry_att))
                        {
                            source_attribute.symmetry_inv.RemoveAt(i);
                            break;
                        }
                    }
                }
                //MisUseAnObjectsDB.deleteSymmetryWithAttribute(att_name, symmetry_att, MainWindow.clusterName);                
                reloadImpliedFromToList(source_attribute);
            }
        }
        public void del_impliedFrom_Checked(object sender, RoutedEventArgs e)
        {
            CheckBox d_cb = (CheckBox)sender;
            string tag_id = (string)d_cb.Tag;

            MessageBoxResult result = MessageBox.Show(this, "delete " + tag_id,
                            "Confirm delete", MessageBoxButton.YesNo,
                            MessageBoxImage.Information);

            if (result == MessageBoxResult.No)
            {
                d_cb.IsChecked = false;
            }
            else
            {
                string[] imp_atts = tag_id.Split('→');
                string att_name = imp_atts[1].Trim();
                string implied_from_att = imp_atts[0].Trim();

                bool deleted = false;
                for (int i = 0; i < source_attribute.implied_from.Count; i++)
                {
                    if (source_attribute.implied_from[i].name.Equals(implied_from_att))
                    {
                        source_attribute.implied_from.RemoveAt(i);
                        deleted = true;
                        break;
                    }
                }

                if (deleted == false)
                {
                    for (int i = 0; i < source_attribute.implied_from_inv.Count; i++)
                    {
                        if (source_attribute.implied_from_inv[i].name.Equals(implied_from_att))
                        {
                            source_attribute.implied_from_inv.RemoveAt(i);
                            break;
                        }
                    }
                }
                //MisUseAnObjectsDB.deleteImpliedFromWithAttribute(att_name, implied_from_att, MainWindow.clusterName);                
                reloadImpliedFromToList(source_attribute);
            }
        }
        
        private bool containInPara(Paragraph p4, string s_str)
        {
            bool contained = false;
            TextRange allTextRange = new TextRange(p4.ContentStart, p4.ContentEnd);
            string p_s = allTextRange.Text;
            if (p_s.Contains(s_str))
            {
                contained = true;                
            }
            return contained;
        }

        private bool attributeAlreadyExist()
        {
            if (isNewAttribute == false)
            {
                return false;
            }
            string att_n = null;
            if (att_name_cb.SelectedItem != null)
            {
                att_n = att_name_cb.SelectedItem.ToString();
            }
            else
            {
                att_n = att_name_cb.Text;
            }
            //att_n = att_name_cb.Text;

            //if (att_n == null || att_n.Equals(""))
            //{
            //    att_n = att_name_cb.SelectedItem.ToString();
            //}

            att_n = att_n.Trim();
            att_n = att_n.TrimEnd('\n');
            att_n = att_n.TrimEnd('\r');

            att_n = att_n.Trim();
            att_n = att_n.TrimEnd('\n');
            att_n = att_n.TrimEnd('\r');           

            foreach (string attributeName in attributeNames)
            {
                if (attributeName.Equals(att_n))
                {
                    return true;
                }
            }
            return false;
        }

        private bool allPrimaryCompsSelected()
        {
            string att_n = null;
            if (att_name_cb.SelectedItem != null)
            {
                att_n = att_name_cb.SelectedItem.ToString();
            }
            else
            {
                att_n = att_name_cb.Text;
            }
            //att_n = att_name_cb.Text;

            //if (att_n == null || att_n.Equals(""))
            //{
            //    att_n = att_name_cb.SelectedItem.ToString();
            //}

            att_n = att_n.Trim();
            att_n = att_n.TrimEnd('\n');
            att_n = att_n.TrimEnd('\r');

            att_n = att_n.Trim();
            att_n = att_n.TrimEnd('\n');
            att_n = att_n.TrimEnd('\r');

            string att_n_value = null;
            ComboBoxItem cbi = (ComboBoxItem)attributeValue_cb.SelectedItem;

            if (cbi != null)
            {
                att_n_value = (string)cbi.Content;
                att_n_value = att_n_value.Trim();
                att_n_value = att_n_value.TrimEnd('\n');
                att_n_value = att_n_value.TrimEnd('\r');
            }

            string att_n_obfuscation = null;
            ComboBoxItem cbo = (ComboBoxItem)obfuscation_level_cb.SelectedItem;
            if (cbo != null)
            {
                att_n_obfuscation = (string)cbo.Content;

                att_n_obfuscation = att_n_obfuscation.Trim();
                att_n_obfuscation = att_n_obfuscation.TrimEnd('\n');
                att_n_obfuscation = att_n_obfuscation.TrimEnd('\r');
            }           
                        
            string description = att_description.Text;
            
            string literal_t = "";
            if (string_l.IsChecked == true)
            {
                literal_t = "[string]";
            }
            else if (numeric_l.IsChecked == true)
            {
                literal_t = "[numeric]";
            }
            else if (boolean_l.IsChecked == true)
            {
                literal_t = "[boolean]";
            }

            string category_t = "";
            if (categoryAgent.IsChecked == true)
            {
                category_t = "agentAttribute";
            }
            else if (categoryEnvironmental.IsChecked == true)
            {
                category_t = "environmentalAttribute";
            }
            else if (categoryRegulatory.IsChecked == true)
            {
                category_t = "regulatoryAttribute";
            }

            //string isPrivate_a = "";
            //bool ispr_a = false;
            //if (yes_p_rd.IsChecked == true)
            //{
            //    isPrivate_a = "true";
            //    ispr_a = true;
            //}
            //else if(no_p_rd.IsChecked == true)
            //{
            //    isPrivate_a = "false";
            //    ispr_a = false;
            //}

            //string personallyIdentifiable_a = "";
            //bool pid = false;
            //if (per_id_rd_y.IsChecked == true)
            //{
            //    personallyIdentifiable_a = "true";
            //    pid = true;
            //}
            //else
            //{
            //    personallyIdentifiable_a = "false";
            //    pid = false;
            //}

            if (ci_ == null && eew_ == null)
            {
                //if (literal_t.Length > 0 && category_t.Length > 0 &&
                //    isPrivate_a.Length > 0 && personallyIdentifiable_a.Length > 0)
                if (literal_t.Length > 0 && category_t.Length > 0)
                {
                    x_attribute = new Attribute();
                    x_attribute.name = att_n;
                    x_attribute.description = description;
                    x_attribute.literalType = literal_t;
                    x_attribute.category = category_t;
                    //x_attribute.isPrivate = ispr_a;
                    //x_attribute.personallyIdentifiable = pid;

                    if (att_n_value.Equals("veryLow"))
                    {
                        x_attribute.sensitivityLevel = Attribute.Sensitivity.veryLow;
                    }
                    else if (att_n_value.Equals("low"))
                    {
                        x_attribute.sensitivityLevel = Attribute.Sensitivity.low;
                    }
                    else if (att_n_value.Equals("medium"))
                    {
                        x_attribute.sensitivityLevel = Attribute.Sensitivity.medium;
                    }
                    else if (att_n_value.Equals("high"))
                    {
                        x_attribute.sensitivityLevel = Attribute.Sensitivity.high;
                    }
                    else if (att_n_value.Equals("veryHigh"))
                    {
                        x_attribute.sensitivityLevel = Attribute.Sensitivity.veryHigh;
                    }
                    //source_attribute.attributeValue = att_n_value;

                    if (att_n_obfuscation.Equals("AccuratePrecise"))
                    {
                        x_attribute.obfuscationLevel = Attribute.Obfuscation.AccuratePrecise;
                    }
                    else if (att_n_obfuscation.Equals("AccurateImprecise"))
                    {
                        x_attribute.obfuscationLevel = Attribute.Obfuscation.AccurateImprecise;
                    }
                    else if (att_n_obfuscation.Equals("InaccuratePrecise"))
                    {
                        x_attribute.obfuscationLevel = Attribute.Obfuscation.InaccuratePrecise;
                    }
                    else if (att_n_obfuscation.Equals("InccurateImprecise"))
                    {
                        x_attribute.obfuscationLevel = Attribute.Obfuscation.InccurateImprecise;
                    }

                    x_attribute.clusterName = MainWindow.clusterName;
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                //if (literal_t.Length > 0 && category_t.Length > 0 &&
                //    personallyIdentifiable_a.Length > 0)
                if (literal_t.Length > 0 && category_t.Length > 0)
                {
                    x_attribute = new Attribute();
                    x_attribute.name = att_n;
                    x_attribute.description = description;
                    x_attribute.literalType = literal_t;
                    x_attribute.category = category_t;
                    //x_attribute.isPrivate = ispr_a;
                    //x_attribute.personallyIdentifiable = pid;
                    if (att_n_value.Equals("veryLow"))
                    {
                        x_attribute.sensitivityLevel = Attribute.Sensitivity.veryLow;
                    }
                    else if (att_n_value.Equals("low"))
                    {
                        x_attribute.sensitivityLevel = Attribute.Sensitivity.low;
                    }
                    else if (att_n_value.Equals("medium"))
                    {
                        x_attribute.sensitivityLevel = Attribute.Sensitivity.medium;
                    }
                    else if (att_n_value.Equals("high"))
                    {
                        x_attribute.sensitivityLevel = Attribute.Sensitivity.high;
                    }
                    else if (att_n_value.Equals("veryHigh"))
                    {
                        x_attribute.sensitivityLevel = Attribute.Sensitivity.veryHigh;
                    }
                    //source_attribute.attributeValue = att_n_value;

                    if (att_n_obfuscation.Equals("AccuratePrecise"))
                    {
                        x_attribute.obfuscationLevel = Attribute.Obfuscation.AccuratePrecise;
                    }
                    else if (att_n_obfuscation.Equals("AccurateImprecise"))
                    {
                        x_attribute.obfuscationLevel = Attribute.Obfuscation.AccurateImprecise;
                    }
                    else if (att_n_obfuscation.Equals("InaccuratePrecise"))
                    {
                        x_attribute.obfuscationLevel = Attribute.Obfuscation.InaccuratePrecise;
                    }
                    else if (att_n_obfuscation.Equals("InccurateImprecise"))
                    {
                        x_attribute.obfuscationLevel = Attribute.Obfuscation.InccurateImprecise;
                    }
                    x_attribute.clusterName = MainWindow.clusterName;
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }

        void del_b_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show("Confirm delete...", "Delete", MessageBoxButton.YesNo, MessageBoxImage.Question);
            if (result == MessageBoxResult.No)
            {
                return;
            }

            Button d_b = (Button)sender;
            Attribute tag_id = (Attribute)d_b.Tag;

            int no_rows = aaw_.actor_atts_lb.Items.Count;
            for (int x = 0; x < no_rows; x++)
            {
                ListBoxItem tr = (ListBoxItem)aaw_.actor_atts_lb.Items.GetItemAt(x);
                Attribute tag_id_r = (Attribute)tr.Tag;
                if ((tag_id_r != null && tag_id != null) && tag_id_r.name.Equals(tag_id.name))
                {
                    aaw_.actor_atts_lb.Items.Remove(aaw_.actor_atts_lb.Items.GetItemAt(x));
                    break;
                }
            }
        }

        private void aggregates_from_to_b_Click(object sender, RoutedEventArgs e)
        {
            if (att_name_cb.Text == null)
            {
                MessageBox.Show("Missing attribute name...", "Error", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            else if (att_name_cb.Text.Trim().Equals(""))
            {
                MessageBox.Show("Missing attribute name...", "Error", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            else if (attributeAlreadyExist() == true)
            {
                MessageBox.Show("Attribute Name duplicate !", "Error", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            else if(allPrimaryCompsSelected() == false)
            {
                MessageBox.Show("unchecked property!", "Error", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            //att_name_cb.IsEditable = false;
            att_name_cb.IsEnabled = false;

            MisUseAnObjectsDB.addAttributeDB(x_attribute, MainWindow.clusterName);//intermediary attribute addition

            AddAggregateFromToAttributeWindow1 aaftaw = new AddAggregateFromToAttributeWindow1(this, x_attribute);
            aaftaw.Owner = (Window)this.Parent;
            aaftaw.ShowDialog();
        }

        private void reloadAttInComboBox()
        {
            List<Attribute> attributes = MisUseAnObjectsDB.loadAllAttributes(MainWindow.clusterName);
            foreach(Attribute att in attributes)
            {
                att_name_cb.Items.Add(att.name);
            }            
        }

        private void reloadImpliedFromToList(Attribute iter)
        {
            //implied_from_listBox.Items.Clear();
            att_aggregation_listBox.Items.Clear();
            
            containedimplications = new List<string>();
            containedaggregations = new List<string>();

            //add bi-directional (symmetry) items to implied_from_listBox   
            if (iter != null && iter.symmetry.Count > 0)
            {
                Xthis(iter);
                Ythis(iter);
                Zthis(iter);
            }
            if (iter != null && iter.symmetry_inv.Count > 0)
            {
                XthisInv(iter);
                YthisInv(iter);
                ZthisInv(iter);
            }

            //add uni-directional (X->Y) items to implied_from_listBox 
            if (iter != null && iter.implied_to.Count > 0)
            {
                Xthis(iter);
                Ythis(iter);
                Zthis(iter);
            }
            if (iter != null && iter.implied_to_inv.Count > 0)
            {
                XthisInv(iter);
                YthisInv(iter);
                ZthisInv(iter);
            }

            //add uni-directional (Y->X) items to implied_from_listBox  
            if (iter != null && iter.implied_from.Count > 0)
            {
                Xthis(iter);
                Ythis(iter);
                Zthis(iter);
            }
            if (iter != null && iter.implied_from_inv.Count > 0)
            {
                XthisInv(iter);
                YthisInv(iter);
                ZthisInv(iter);
            }

            if (iter != null && iter.implied_from.Count == 0 && iter.implied_from_inv.Count == 0
                && iter.implied_to.Count == 0 && iter.implied_to_inv.Count == 0
                && iter.symmetry.Count == 0 && iter.symmetry_inv.Count == 0)
            {
                MisUseAnObjectsDB.loadAggregateAttributes(iter, MainWindow.clusterName);
                foreach (string ss in iter.aggregation_statements)
                {
                    bool contained = false;
                    foreach (string aggregation in containedaggregations)
                    {
                        if (aggregation.Equals(ss))
                        {
                            contained = true;
                            break;
                        }
                    }
                    if (contained == false)
                    {
                        containedaggregations.Add(ss);

                        CheckBox cb = new CheckBox();
                        cb.Tag = ss;
                        cb.Content = ss;
                        cb.AddHandler(CheckBox.CheckedEvent, new RoutedEventHandler(del_aggregation_Checked));
                        att_aggregation_listBox.Items.Add(cb);
                    }
                }
            }
        }

        public void reloadAggregationList(Attribute att)
        {
            att_aggregation_listBox.Items.Clear();
            containedaggregations = new List<string>();

            foreach (string agg_s in att.aggregation_statements)
            {
                bool contained = false;
                foreach (string aggregation in containedaggregations)
                {
                    if (aggregation.Equals(agg_s))
                    {
                        contained = true;
                        break;
                    }
                }
                if (contained == false)
                {
                    containedaggregations.Add(agg_s);

                    CheckBox cb = new CheckBox();
                    cb.Tag = agg_s;
                    cb.Content = agg_s;
                    cb.AddHandler(CheckBox.CheckedEvent, new RoutedEventHandler(del_aggregation_Checked));
                    att_aggregation_listBox.Items.Add(cb);
                }
            }
        }

        public void reloadAttributeDomainList(Attribute att)
        {
            att_domain_lb.Items.Clear();

            foreach (string d_s in att.domain)
            {
                bool contained = att_domain_lb.Items.Contains(d_s);
                if (contained == false)
                {
                    CheckBox cb = new CheckBox();
                    cb.Tag = d_s;
                    cb.Content = d_s;
                    cb.AddHandler(CheckBox.CheckedEvent, new RoutedEventHandler(del_domain_Checked));
                    att_domain_lb.Items.Add(cb);                   
                    //att_domain_lb.Items.Add(d_s);
                }
            }
        }

                
       //public void reloadAttTypeOfComboBox()
       // {
       //     type_of_cb.Items.Clear();
       //     List<Attribute> attributes = MisUseAnObjectsDB.loadAllAttributes(MainWindow.clusterName);
       //     foreach (Attribute att in attributes)
       //     {
       //         type_of_cb.Items.Add(att.name);
       //     }  

       // }
        //public void reloadAttributeTypeOfList(Attribute att)
        //{
        //    if (att != null)
        //    {
        //        att_type_of_lb.Items.Clear();

        //        foreach (string to_s in att.type_of)
        //        {
        //            bool contained = att_type_of_lb.Items.Contains(to_s);
        //            if (contained == false)
        //            {
        //                CheckBox cb = new CheckBox();
        //                cb.Tag = to_s;
        //                cb.Content = to_s;
        //                cb.AddHandler(CheckBox.CheckedEvent, new RoutedEventHandler(del_type_of_Checked));
        //                att_type_of_lb.Items.Add(cb);
        //            }
        //        }
        //    }
        //}


        private void del_domain_Checked(object sender, RoutedEventArgs e)
        {
            CheckBox d_cb = (CheckBox)sender;
            string tag_id = (string)d_cb.Tag;

            MessageBoxResult result = MessageBox.Show(this, "delete "+tag_id,
                            "Confirm delete", MessageBoxButton.YesNo,
                            MessageBoxImage.Information);

            if (result == MessageBoxResult.No)
            {
                d_cb.IsChecked = false;
            }
            else
            {
                for (int i = 0; i < source_attribute.domain.Count; i++)
                {
                    if (source_attribute.domain[i].Equals(tag_id))
                    {
                        source_attribute.domain.RemoveAt(i);
                        break;
                    }
                }
                MisUseAnObjectsDB.deleteConstraintAttribute(source_attribute.name, tag_id, MainWindow.clusterName);
                string att_n = null;
                if (att_name_cb.SelectedItem != null)
                {
                    att_n = att_name_cb.SelectedItem.ToString();
                }
                else
                {
                    att_n = att_name_cb.Text;
                }
                //Attribute attx = MisUseAnObjectsDB.loadAttributeFull(att_n);                
                reloadAttributeDomainList(source_attribute);
            }
        }

        //private void del_type_of_Checked(object sender, RoutedEventArgs e)
        //{
        //    CheckBox d_cb = (CheckBox)sender;
        //    string tag_id = (string)d_cb.Tag;

        //    MessageBoxResult result = MessageBox.Show(this, "delete "+tag_id,
        //                    "Confirm delete", MessageBoxButton.YesNo,
        //                    MessageBoxImage.Information);

        //    if (result == MessageBoxResult.No)
        //    {
        //        d_cb.IsChecked = false;
        //    }
        //    else
        //    {
        //        for (int i = 0; i < source_attribute.type_of.Count; i++)
        //        {
        //            if (source_attribute.type_of[i].Equals(tag_id))
        //            {
        //                source_attribute.type_of.RemoveAt(i);
        //                break;
        //            }
        //        }
        //        MisUseAnObjectsDB.deleteTypeOfAttribute(source_attribute.name, tag_id, MainWindow.clusterName);
        //        type_of_cb.Text = "";               
        //        reloadAttributeTypeOfList(source_attribute);
        //        reloadAttTypeOfComboBox();
        //    }
        //}
        
        private void name_cb_selection_changed(object sender, SelectionChangedEventArgs e)
        {
            //string att_name = imp_att_name_cb.Text;
            //string att_name = imp_att_name_cb.SelectedItem.ToString();

            //string att_name = "";
            if (att_name_cb.SelectedItem != null)
            {
                attName = att_name_cb.SelectedItem.ToString();
            }
            else
            {
                attName = att_name_cb.Text;
            }

            attName = attName.Trim();
            attName = attName.TrimEnd('\n');
            attName = attName.TrimEnd('\r');

            //string description = att_description.Text;
            //description = description.TrimEnd('\n');
            //description = description.TrimEnd('\r');
            
            Attribute attribute = null;
            if (attName.Count() > 0)
            {
                string attn = attName;
                attribute = MisUseAnObjectsDB.loadAttributeFull(attn, MainWindow.clusterName);
            }

            if (attribute != null)
            {
                //if (attribute.personallyIdentifiable == true)
                //{
                //    per_id_rd_y.IsChecked = true;
                //}
                //else
                //{
                //    per_id_rd_n.IsChecked = true;
                //}

                //per_id_rd_y.IsEnabled = false;
                //per_id_rd_n.IsEnabled = false;

                if (attribute.literalType.Equals("[string]"))
                {
                    string_l.IsChecked = true;
                }
                else if (attribute.literalType.Equals("[numeric]"))
                {
                    numeric_l.IsChecked = true;
                }
                else if (attribute.literalType.Equals("[boolean]"))
                {
                    boolean_l.IsChecked = true;
                }
                string_l.IsEnabled = false;
                numeric_l.IsEnabled = false;
                boolean_l.IsEnabled = false;

                if (attribute.category.Equals("environmentalAttribute"))
                {
                    categoryEnvironmental.IsChecked = true;
                }
                else if (attribute.category.Equals("regulatoryAttribute"))
                {
                    categoryRegulatory.IsChecked = true;
                }
                else if (attribute.category.Equals("agentAttribute"))
                {
                    categoryAgent.IsChecked = true;
                }
                categoryEnvironmental.IsEnabled = false;
                categoryRegulatory.IsEnabled = false;
                categoryAgent.IsEnabled = false;

                if (attribute.sensitivityLevel == Attribute.Sensitivity.veryLow)
                {
                    attributeValue_cb.Text = "veryLow";
                    attributeValue_cb.Tag = "veryLow";
                }
                else if (attribute.sensitivityLevel == Attribute.Sensitivity.low)
                {
                    attributeValue_cb.Text = "low";
                    attributeValue_cb.Tag = "low";
                }
                else if (attribute.sensitivityLevel == Attribute.Sensitivity.medium)
                {
                    attributeValue_cb.Text = "medium";
                    attributeValue_cb.Tag = "medium";
                }
                else if (attribute.sensitivityLevel == Attribute.Sensitivity.high)
                {
                    attributeValue_cb.Text = "high";
                    attributeValue_cb.Tag = "high";
                }
                else if (attribute.sensitivityLevel == Attribute.Sensitivity.veryHigh)
                {
                    attributeValue_cb.Text = "veryHigh";
                    attributeValue_cb.Tag = "veryHigh";
                }

                if (attribute.obfuscationLevel == Attribute.Obfuscation.AccuratePrecise)
                {
                    obfuscation_level_cb.Text = "AccuratePrecise";
                    obfuscation_level_cb.Tag = "AccuratePrecise";
                }
                else if (attribute.obfuscationLevel == Attribute.Obfuscation.AccurateImprecise)
                {
                    obfuscation_level_cb.Text = "AccurateImprecise";
                    obfuscation_level_cb.Tag = "AccurateImprecise";
                }
                else if (attribute.obfuscationLevel == Attribute.Obfuscation.InaccuratePrecise)
                {
                    obfuscation_level_cb.Text = "InaccuratePrecise";
                    obfuscation_level_cb.Tag = "InaccuratePrecise";
                }
                else if (attribute.obfuscationLevel == Attribute.Obfuscation.InccurateImprecise)
                {
                    obfuscation_level_cb.Text = "InccurateImprecise";
                    obfuscation_level_cb.Tag = "InccurateImprecise";
                }
                
                att_description.Text = attribute.description;
                att_description.IsEnabled = false;

                aggregates_from_to_b.IsEnabled = false;
                //implied_from_to_b.IsEnabled = false;

                reloadImpliedFromToList(attribute);
                reloadAttributeDomainList(attribute);
                //reloadAttTypeOfComboBox();
                //reloadAttributeTypeOfList(source_attribute);

                //MisUseAnObjectsDB.loadAggregateAttributes(attribute);
                //reloadAggregationList(attribute);
            }
            else
            {
                string_l.IsEnabled = true;
                numeric_l.IsEnabled = true;
                boolean_l.IsEnabled = true;

                //per_id_rd_y.IsEnabled = true;
                //per_id_rd_n.IsEnabled = true;

                categoryEnvironmental.IsEnabled = true;
                categoryRegulatory.IsEnabled = true;
                categoryAgent.IsEnabled = true;
                att_description.IsEnabled = true;
                
                aggregates_from_to_b.IsEnabled = true;
                //implied_from_to_b.IsEnabled = true;

                //implied_from_listBox.Items.Clear();
                att_aggregation_listBox.Items.Clear();
                att_domain_lb.Items.Clear();
                //type_of_cb.Items.Clear();
                //att_type_of_lb.Items.Clear();
            }
        }

        private void key_pressed_name_cb(object sender, KeyEventArgs e)
        {
            attName = att_name_cb.Text;

            //if (att_name_cb.SelectedItem != null)
            //{
            //    attName = att_name_cb.SelectedItem.ToString();
            //}
            //else
            //{
            //    attName = att_name_cb.Text;
            //}

            //attName = att_name_cb.Text;

            //if (attName == null || attName.Equals(""))
            //{
            //    attName = att_name_cb.SelectedItem.ToString();
            //}

            Attribute attribute = null;
            if (attName.Count() > 0)
            {
                string attn = attName;
                attribute = MisUseAnObjectsDB.loadAttributeFull(attn, MainWindow.clusterName);
            }

            if (attribute != null)
            {
                //if (attribute.personallyIdentifiable == true)
                //{
                //    per_id_rd_y.IsChecked = true;
                //}
                //else
                //{
                //    per_id_rd_n.IsChecked = true;
                //}
                //per_id_rd_y.IsEnabled = false;
                //per_id_rd_n.IsEnabled = false;

                if (attribute.literalType.Equals("[string]"))
                {
                    string_l.IsChecked = true;
                }
                else if (attribute.literalType.Equals("[numeric]"))
                {
                    numeric_l.IsChecked = true;
                }
                else if (attribute.literalType.Equals("[boolean]"))
                {
                    boolean_l.IsChecked = true;
                }
                string_l.IsEnabled = false;
                numeric_l.IsEnabled = false;
                boolean_l.IsEnabled = false;

                if (attribute.category.Equals("environmentalAttribute"))
                {
                    categoryEnvironmental.IsChecked = true;
                }
                else if (attribute.category.Equals("regulatoryAttribute"))
                {
                    categoryRegulatory.IsChecked = true;
                }
                else if (attribute.category.Equals("agentAttribute"))
                {
                    categoryAgent.IsChecked = true;
                }
                categoryEnvironmental.IsEnabled = false;
                categoryRegulatory.IsEnabled = false;
                categoryAgent.IsEnabled = false;

                if (attribute.sensitivityLevel == Attribute.Sensitivity.veryLow)
                {
                    attributeValue_cb.Text = "veryLow";
                    attributeValue_cb.Tag = "veryLow";
                }
                else if (attribute.sensitivityLevel == Attribute.Sensitivity.low)
                {
                    attributeValue_cb.Text = "low";
                    attributeValue_cb.Tag = "low";
                }
                else if (attribute.sensitivityLevel == Attribute.Sensitivity.medium)
                {
                    attributeValue_cb.Text = "medium";
                    attributeValue_cb.Tag = "medium";
                }
                else if (attribute.sensitivityLevel == Attribute.Sensitivity.high)
                {
                    attributeValue_cb.Text = "high";
                    attributeValue_cb.Tag = "high";
                }
                else if (attribute.sensitivityLevel == Attribute.Sensitivity.veryHigh)
                {
                    attributeValue_cb.Text = "veryHigh";
                    attributeValue_cb.Tag = "veryHigh";
                }

                if (attribute.obfuscationLevel == Attribute.Obfuscation.AccuratePrecise)
                {
                    obfuscation_level_cb.Text = "AccuratePrecise";
                    obfuscation_level_cb.Tag = "AccuratePrecise";
                }
                else if (attribute.obfuscationLevel == Attribute.Obfuscation.AccurateImprecise)
                {
                    obfuscation_level_cb.Text = "AccurateImprecise";
                    obfuscation_level_cb.Tag = "AccurateImprecise";
                }
                else if (attribute.obfuscationLevel == Attribute.Obfuscation.InaccuratePrecise)
                {
                    obfuscation_level_cb.Text = "InaccuratePrecise";
                    obfuscation_level_cb.Tag = "InaccuratePrecise";
                }
                else if (attribute.obfuscationLevel == Attribute.Obfuscation.InccurateImprecise)
                {
                    obfuscation_level_cb.Text = "InccurateImprecise";
                    obfuscation_level_cb.Tag = "InccurateImprecise";
                }
                //attributeValue_cb.Text = attribute.attributeValue;

                att_description.Text = attribute.description;
                att_description.IsEnabled = false;
                
                aggregates_from_to_b.IsEnabled = false;
                //implied_from_to_b.IsEnabled = false;

                reloadImpliedFromToList(attribute);

                reloadAttributeDomainList(attribute);
                //reloadAttTypeOfComboBox();
                //reloadAttributeTypeOfList(source_attribute);

                //MisUseAnObjectsDB.loadAggregateAttributes(attribute);
                //reloadAggregationList(attribute);
            }
            else
            {
                string_l.IsEnabled = true;
                numeric_l.IsEnabled = true;
                boolean_l.IsEnabled = true;

                //per_id_rd_y.IsEnabled = true;
                //per_id_rd_n.IsEnabled = true;

                categoryEnvironmental.IsEnabled = true;
                categoryRegulatory.IsEnabled = true;
                categoryAgent.IsEnabled = true;

                att_description.IsEnabled = true;
                
                aggregates_from_to_b.IsEnabled = true;
                //implied_from_to_b.IsEnabled = true;

                //implied_from_listBox.Items.Clear();
                att_aggregation_listBox.Items.Clear();
                att_domain_lb.Items.Clear();
                //type_of_cb.Items.Clear();
                //att_type_of_lb.Items.Clear();
            }
        }

        private void att_domain_b_Click(object sender, RoutedEventArgs e)
        {
            if (att_name_cb.Text == null)
            {
                MessageBox.Show("Missing attribute name...", "Error", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            else if (att_name_cb.Text.Trim().Equals(""))
            {
                MessageBox.Show("Missing attribute name...", "Error", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            else if (attributeAlreadyExist() == true)
            {
                MessageBox.Show("Attribute Name duplicate !", "Error", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            else if (allPrimaryCompsSelected() == false)
            {
                MessageBox.Show("unchecked property!", "Error", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            //att_name_cb.IsEditable = false;
            att_name_cb.IsEnabled = false;
            att_description.IsEnabled = false;

            if (source_attribute == null)
            {
                createSourceAtt();
            }
            MisUseAnObjectsDB.addAttributeDB(source_attribute, MainWindow.clusterName);//intermediary attribute addition

            AddConstraintWindow acw = new AddConstraintWindow(this, source_attribute);
            acw.Owner = (Window)this.Parent;
            acw.ShowDialog();
        }

        //private void att_type_of_b_Click(object sender, RoutedEventArgs e)
        //{
        //    if (att_name_cb.Text == null)
        //    {
        //        MessageBox.Show("Missing attribute name...", "Error", MessageBoxButton.OK, MessageBoxImage.Information);
        //        return;
        //    }
        //    else if (att_name_cb.Text.Trim().Equals(""))
        //    {
        //        MessageBox.Show("Missing attribute name...", "Error", MessageBoxButton.OK, MessageBoxImage.Information);
        //        return;
        //    }

        //    else if (allPrimaryCompsSelected() == false)
        //    {
        //        MessageBox.Show("unchecked property!", "Error", MessageBoxButton.OK, MessageBoxImage.Information);
        //        return;
        //    }
        //    string type_of = "";
        //    if (type_of_cb.SelectedItem != null)
        //    {
        //        type_of = type_of_cb.SelectedItem.ToString();
        //    }
        //    else
        //    {
        //        type_of = type_of_cb.Text;
        //    }

        //    type_of = type_of.Trim();
        //    type_of = type_of.TrimEnd('\n');
        //    type_of = type_of.TrimEnd('\r');

        //    if (type_of.Length == 0)
        //    {
        //        MessageBox.Show("Select the type of attribute!", "Error", MessageBoxButton.OK, MessageBoxImage.Information);
        //        return;
        //    }
        //    else if (type_of.Equals(source_attribute.name))
        //    {
        //        MessageBox.Show("An attribute cannot be a type of itself!", "Error", MessageBoxButton.OK, MessageBoxImage.Information);
        //        return;
        //    }

        //    //att_name_cb.IsEditable = false;
        //    att_name_cb.IsEnabled = false;
        //    att_description.IsEnabled = false;

        //    if (source_attribute == null)
        //    {
        //        createSourceAtt();
        //    }
        //    MisUseAnObjectsDB.addAttributeDB(source_attribute, MainWindow.clusterName);//intermediary attribute addition

        //    source_attribute.addTypeOf(type_of);
        //    MisUseAnObjectsDB.addAttributeTypeOf(source_attribute.name, type_of, MainWindow.clusterName);
        //    reloadAttributeTypeOfList(source_attribute);
        //}

        private void createSourceAtt()
        {

            if (source_attribute == null)
            {
                source_attribute = new Attribute();
                source_attribute.clusterName = MainWindow.clusterName;
            }

            //string att_n = att_name_cb.Text;

            string att_n = null;
            if (att_name_cb.SelectedItem != null)
            {
                att_n = att_name_cb.SelectedItem.ToString();
            }
            else
            {
                att_n = att_name_cb.Text;
            }

            //att_n = att_name_cb.Text;

            //if (att_n == null || att_n.Equals(""))
            //{
            //    att_n = att_name_cb.SelectedItem.ToString();
            //}

            att_n = att_n.Trim();
            att_n = att_n.TrimEnd('\n');
            att_n = att_n.TrimEnd('\r');

            string att_n_value = "low";
            ComboBoxItem cbi = (ComboBoxItem)attributeValue_cb.SelectedItem;
            if (cbi != null)
            {
                att_n_value = (string)cbi.Content;

                att_n_value = att_n_value.Trim();
                att_n_value = att_n_value.TrimEnd('\n');
                att_n_value = att_n_value.TrimEnd('\r');
            }           

            string description = att_description.Text;
            description = description.TrimEnd('\n');
            description = description.TrimEnd('\r');

            string literal_t = "";
            if (string_l.IsChecked == true)
            {
                literal_t = "[string]";
            }
            else if (numeric_l.IsChecked == true)
            {
                literal_t = "[numeric]";
            }
            else if (boolean_l.IsChecked == true)
            {
                literal_t = "[boolean]";
            }

            string category_t = "";
            if (categoryAgent.IsChecked == true)
            {
                category_t = "agentAttribute";
            }
            else if (categoryEnvironmental.IsChecked == true)
            {
                category_t = "environmentalAttribute";
            }
            else if (categoryRegulatory.IsChecked == true)
            {
                category_t = "regulatoryAttribute";
            }

            //bool isPrivate_a;
            //if (yes_p_rd.IsChecked == true)
            //{
            //    isPrivate_a = true;
            //}
            //else
            //{
            //    isPrivate_a = false;
            //}

            //bool personallyIdentifiable_a;
            //if (per_id_rd_y.IsChecked == true)
            //{
            //    personallyIdentifiable_a = true;
            //}
            //else
            //{
            //    personallyIdentifiable_a = false;
            //}
            source_attribute.name = att_n;
            source_attribute.description = description;
            source_attribute.literalType = literal_t;
            //source_attribute.isPrivate = isPrivate_a;
            //source_attribute.personallyIdentifiable = personallyIdentifiable_a;
            source_attribute.category = category_t;

            if (source_attribute.sensitivityLevel == Attribute.Sensitivity.veryLow)
            {
                attributeValue_cb.Text = "veryLow";
                attributeValue_cb.Tag = "veryLow";
            }
            else if (source_attribute.sensitivityLevel == Attribute.Sensitivity.low)
            {
                attributeValue_cb.Text = "low";
                attributeValue_cb.Tag = "low";
            }
            else if (source_attribute.sensitivityLevel == Attribute.Sensitivity.medium)
            {
                attributeValue_cb.Text = "medium";
                attributeValue_cb.Tag = "medium";
            }
            else if (source_attribute.sensitivityLevel == Attribute.Sensitivity.high)
            {
                attributeValue_cb.Text = "high";
                attributeValue_cb.Tag = "high";
            }
            else if (source_attribute.sensitivityLevel == Attribute.Sensitivity.veryHigh)
            {
                attributeValue_cb.Text = "veryHigh";
                attributeValue_cb.Tag = "veryHigh";
            }

            if (source_attribute.obfuscationLevel == Attribute.Obfuscation.AccuratePrecise)
            {
                obfuscation_level_cb.Text = "AccuratePrecise";
                obfuscation_level_cb.Tag = "AccuratePrecise";
            }
            else if (source_attribute.obfuscationLevel == Attribute.Obfuscation.AccurateImprecise)
            {
                obfuscation_level_cb.Text = "AccurateImprecise";
                obfuscation_level_cb.Tag = "AccurateImprecise";
            }
            else if (source_attribute.obfuscationLevel == Attribute.Obfuscation.InaccuratePrecise)
            {
                obfuscation_level_cb.Text = "InaccuratePrecise";
                obfuscation_level_cb.Tag = "InaccuratePrecise";
            }
            else if (source_attribute.obfuscationLevel == Attribute.Obfuscation.InccurateImprecise)
            {
                obfuscation_level_cb.Text = "InccurateImprecise";
                obfuscation_level_cb.Tag = "InccurateImprecise";
            }
                
            //source_attribute.attributeValue = att_n_value;
        }
                
    }
}
